c# - asp.net 的 PayPal IPN 沙箱错误

标签 c# asp.net paypal paypal-ipn

我在使用 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/

相关文章:

c# - 如何显示包含一些标签内容的 MessageBox 消息?

c# - 在 .NET 中控制位图的可见性

c# - 使用 json.net 解析 json 字符串?

c# - 业务对象应该包含对象还是引用?

c# - 从原始 HTML/CSS 内容从 ASP.NET 生成 PDF?

c# - 在 gridview 中格式化日期时间字段

jquery - CORS : accessing web services which require authentication (ASP. 网络表格)

java - Paypal HttpHostConnectException

android - 没有 Braintree 的原生移动设备中的 Paypal 结帐集成

api - 如何验证 PayPal 帐户?