简体   繁体   中英

PayPal IPN Sandbox error with asp.net

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM