Reputation: 127
I have a problem with IPN Sandbox and ASP.NET 4.0. The same code that I use for the production part does not work with SandBox.
The error that is raised is as follows:
Exception message: The underlying connection was closed: An unexpected error occurred on a send.
This is the code:
string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
string strResponse_copy = strRequest; //Save a copy of the initial info sent by PayPal
strRequest += "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
The error was raised on the line
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
The code that deals instead of calling the payment page works fine.
How can I fix ?
Upvotes: 0
Views: 153
Reputation: 13648
If the same code works on the production site, but not the Sandbox, it is very likely an intermittent network issue with the Sandbox environment.
I have seen this and related issues with the Sandbox recently. Keep retrying the code, I believe certain requests will go through, and others get dropped.
Upvotes: 1