469,610 Members | 1,494 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

problem in Payment gateway

i am using the link of metacharge.com for payment gateway, when i post data
throung IE it give the correct response, but when i use the .net code to post
data the response is not correct.message is some data is missing.
i use the following code:

public class httpClass

private string UserName;
private string UserPwd;
private string ProxyServer;
private int ProxyPort;
private string Request;

public httpClass(string HttpUserName,
string HttpUserPwd, string HttpProxyServer,
int HttpProxyPort, string HttpRequest)
UserName = HttpUserName;
UserPwd = HttpUserPwd;
ProxyServer = HttpProxyServer;
ProxyPort = HttpProxyPort;
Request = HttpRequest;

/// <summary>
/// This method creates secure/non secure web
/// request based on the parameters passed.
/// </summary>
/// <param name="uri"></param>
/// <param name="collHeader">This parameter of type
/// NameValueCollection may contain any extra header
/// elements to be included in this request </param>
/// <param name="RequestMethod">Value can POST OR GET</param>
/// <param name="NwCred">In case of secure request this would be
/// <returns></returns>
public virtual HttpWebRequest CreateWebRequest(string uri,
NameValueCollection collHeader,
string RequestMethod, bool NwCred)
HttpWebRequest webrequest =
(HttpWebRequest) WebRequest.Create(uri);
webrequest.KeepAlive = false;
webrequest.Method = RequestMethod;

int iCount = collHeader.Count;
string key;
string keyvalue;

for (int i=0; i < iCount; i++)
key = collHeader.Keys[i];
keyvalue = collHeader[i];
webrequest.Headers.Add(key, keyvalue);

webrequest.ContentType = "text/html";

if (ProxyServer.Length 0)
webrequest.Proxy = new
webrequest.AllowAutoRedirect = false;

if (NwCred)
CredentialCache wrCache =
new CredentialCache();
wrCache.Add(new Uri(uri),"Basic",
new NetworkCredential(UserName,UserPwd));
webrequest.Credentials = wrCache;
//Remove collection elements
return webrequest;
}//End of secure CreateWebRequest

/// <summary>
/// This method retreives redirected URL from
/// response header and also passes back
/// any cookie (if there is any)
/// </summary>
/// <param name="webresponse"></param>
/// <param name="Cookie"></param>
/// <returns></returns>
public virtual string GetRedirectURL(HttpWebResponse
webresponse, ref string Cookie)
string uri="";

WebHeaderCollection headers = webresponse.Headers;

if ((webresponse.StatusCode == HttpStatusCode.Found) ||
(webresponse.StatusCode == HttpStatusCode.Redirect) ||
(webresponse.StatusCode == HttpStatusCode.Moved) ||
(webresponse.StatusCode == HttpStatusCode.MovedPermanently))
// Get redirected uri
uri = headers["Location"] ;
uri = uri.Trim();

//Check for any cookies
if (headers["Set-Cookie"] != null)
Cookie = headers["Set-Cookie"];
// string StartURI = "http:/";
// if (uri.Length 0 && uri.StartsWith(StartURI)==false)
// {
// uri = StartURI + uri;
// }
return uri;
}//End of GetRedirectURL method
public virtual string GetFinalResponse(string ReUri,
string Cookie, string RequestMethod, bool NwCred)
NameValueCollection collHeader =
new NameValueCollection();

if (Cookie.Length 0)

HttpWebRequest webrequest =
RequestMethod, NwCred);

BuildReqStream(ref webrequest);

HttpWebResponse webresponse;

webresponse = (HttpWebResponse)webrequest.GetResponse();

Encoding enc = System.Text.Encoding.GetEncoding(1252);
StreamReader loResponseStream = new

string Response = loResponseStream.ReadToEnd();

return Response;

private void BuildReqStream(ref HttpWebRequest webrequest)
//This method build the request stream for WebRequest
Stream oStreamOut= webrequest.GetRequestStream();
byte[] byteArray = Encoding.UTF8.GetBytes(Request);

}//End of HttpBaseClass class
please help me.
Aug 29 '06 #1
0 1061

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by 11abacus | last post: by
15 posts views Thread by Peter Afonin | last post: by
5 posts views Thread by japslam japslam via DotNetMonster.com | last post: by
1 post views Thread by Neven Klofutar | last post: by
2 posts views Thread by =?Utf-8?B?QXNoZmFx?= | last post: by
1 post views Thread by vinodkus | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.