Using WebRequest in PostProcessPayment

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
My code cannot redirect to the bank with WebRequest. here is my code , please help ?

            byte[] buffer = Encoding.UTF8.GetBytes(postdata);
            HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(gServer);
            WebReq.Timeout = 5 * 60 * 1000;

            WebReq.Method = "POST";
            WebReq.ContentType = "application/x-www-form-urlencoded";
            WebReq.ContentLength = buffer.Length;

            WebReq.CookieContainer = new CookieContainer();
            Stream ReqStream = WebReq.GetRequestStream();
            ReqStream.Write(buffer, 0, buffer.Length);

            ReqStream.Close();

            WebResponse WebRes = WebReq.GetResponse();
            Stream ResStream = WebRes.GetResponseStream();
            StreamReader ResReader = new StreamReader(ResStream);
            string responseString = ResReader.ReadToEnd();

            _httpContext.Response.Write(responseString);
7 years ago
Did you copy this code from another payment plugin ?
Here is some code from the commweb payment gateway

// Remove the trailing ampersand on the POST data string
string postDataStr = postData.ToString().Substring(0, postData.Length - 1);

// Get the URL of the Virtual Payment Client
string vpcURL = _commWeb2PartyPaymentSettings.VpcUrl;

// Perform the VPC request (i.e. HTTPS POST) and obtain the VPC response
System.Net.WebClient webClient = new System.Net.WebClient();
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
byte[] response = webClient.UploadData(vpcURL, "POST", Encoding.ASCII.GetBytes(postDataStr));

// Convert the response to a string from a byte array and parse it to extract
// the data using the splitResponse function. Store results in a hashtable.
responseData = System.Text.Encoding.ASCII.GetString(response, 0, response.Length);
responseDecoded = WebUtility.UrlDecode(responseData);
_logger.Information("CommWeb2Party response: " + responseDecoded, null, customer);
System.Collections.Hashtable responseParameters = splitResponse(responseData);
7 years ago
Thanks Yidna but cant find "responseData", "responseDecoded" definition and splitResponse function.

Can you send these too.
7 years ago
Ok I Solved.

Here is the my fault.

I used "_httpcontext" at the end of the code.

Now, I 've changed that into ;

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(responseString);
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();

it is working now.

Thank you.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.