我在使用 IPN 沙盒和 ASP.NET 4.0 时遇到问题。 我用于生产部分的相同代码不适用于 SandBox。
报错如下:
异常消息:底层连接已关闭:发送时发生意外错误。
这是代码:
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();
在线上出现错误
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
处理而不是调用支付页面的代码工作正常。
我该如何解决?
最佳答案
如果相同的代码在生产站点上运行,但在 Sandbox 上不起作用,则很可能是 Sandbox 环境的间歇性网络问题。
我最近看到了这个问题以及沙盒的相关问题。继续重试代码,我相信某些请求会通过,而其他请求会被丢弃。
关于c# - asp.net 的 PayPal IPN 沙箱错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37828580/