我正在尝试使用IPN模拟器测试我的IPN侦听器,但我总是收到“错误请求”错误。
我已经看到了这个答案:
PayPal IPN Bad Request 400 Error Paypal SandBox IPN always returns INVALID
对于我的网站,我使用的代码可以在这里找到:http://www.markstraley.com/Code/PayPalIPN
在其他人的答案中思考,也许这段代码有问题,但我不知道是什么,如果有什么不对的话:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
//must keep the original intact and pass back to PayPal with a _notify-validate command
string data = Encoding.ASCII.GetString(parameters);
data += "&cmd=_notify-validate";
webRequest.ContentLength = data.Length;
//Send the request to PayPal and get the response
using (StreamWriter streamOut = new StreamWriter(webRequest.GetRequestStream(),System.Text.Encoding.ASCII))
{
streamOut.Write(data);
streamOut.Close();
}
我在这段代码中已经想到了,因为我看到其他的asnwers已经用请求的标题解决了,但是我不知道这个代码对于PayPal是否正确。我已经看过paypal代码示例,但所有这些都是VB或webforms。
感谢您的帮助。
注意:我将我的应用程序放在服务器中进行测试,我没有尝试从IPN模拟器调用我的localhost。
答案 0 :(得分:0)
最后,我使用适用于Chrome的应用“高级休息客户端”模拟自己来自PayPal的帖子数据:https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo
我想从PayPal进行测试,但现在已经足够了。感谢Matt的回答:https://stackoverflow.com/a/19941501