c# - 无法连接到 PayPal 沙盒以验证 IPN 监听器收到的消息

标签 c# asp.net paypal paypal-sandbox paypal-ipn

我正在使用 IPN 模拟器测试我的 IPN 监听器。在 IPN 模拟器上发送 IPN 后,我的日志显示我的 IPN 监听器收到了 IPN,但是当它发回添加了 cmd=_notify-validate 的消息时,沙箱没有响应。 IPN 模拟器上显示的错误是“IPN Delivery Failed:500 Internal Server Error”。我的监听器向沙箱发送消息后遇到以下错误:“连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机未能响应 173.0.82.77:443 ”。

当我使用实时 PayPal URL 测试我的监听器时,它以“无效”消息响应 - 这表明我的监听器工作正常。

在与我的网络托管公司核实后,他们告知 PayPal 沙盒 IP 未被阻止,问题应该出在 PayPal 沙盒上。请告知 PayPal 是否有可能阻止了源 IP,因此没有响应它。如果是这样,我怎样才能解封源IP?任何帮助表示赞赏。谢谢。

我正在使用 PayPal 为我的 IPN 监听器提供的示例 ASP.NET C# 代码,我的日志在“正在向 PayPal 发送请求...”处停止。

SSLogger.logger.Info("IPN Invoked");

//Post back to either sandbox or live
string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
string strLive = "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);

//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param = Request.BinaryRead(Request.ContentLength);   //get request values
string strRequest = "cmd=_notify-validate&" + Encoding.ASCII.GetString(param);

//set request values
req.ContentLength = strRequest.Length;
SSLogger.logger.Info("sb: " + Encoding.ASCII.GetString(param));
SSLogger.logger.Info("strRequest: " + strRequest);

//Send the request to PayPal and get the response
SSLogger.logger.Info("Sending request to PayPal...");
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
SSLogger.logger.Info("Request sent out to PayPal.");
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
SSLogger.logger.Info("Response from PayPal received.");

SSLogger.logger.Info(strResponse);

最佳答案

试试这个:

req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
strRequest += "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;

关于c# - 无法连接到 PayPal 沙盒以验证 IPN 监听器收到的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15921181/

相关文章:

java - Paypal证书升级为sha256

c# - 在没有 ThrowIfCancellationRequested 的情况下停止任务

c# - 连续页面 Crystal 报表查看器

c# - 比较对象的不同实现的优点/缺点

javascript - 将 ID 从 GridView 行传递到 Javascript 函数

iphone - 如何使用 PayPalApplicationId

c# - DataGridView 在代码中设置行高并禁用手动调整大小

c# - 我可以迭代数据源吗?

c# - 必须在 (MVC3 + MVC4) 环境中打开 ASP.NET MVC3 项目

Paypal v-零凭证