C# PayPal IPN模拟器错误请求
我试图用IPN模拟器测试我的IPN侦听器,但我总是遇到“坏请求”错误 我已经看到了这些答案: 对于我的网站,我使用的代码可以在这里找到: 在其他答案中思考,可能代码中有错误,但如果有错误,我不知道是什么:C# PayPal IPN模拟器错误请求,c#,asp.net-mvc,paypal,paypal-ipn,C#,Asp.net Mvc,Paypal,Paypal Ipn,我试图用IPN模拟器测试我的IPN侦听器,但我总是遇到“坏请求”错误 我已经看到了这些答案: 对于我的网站,我使用的代码可以在这里找到: 在其他答案中思考,可能代码中有错误,但如果有错误,我不知道是什么: HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Method = "POST"; webRequest.Cont
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模拟器调用我的本地主机。最后,我使用Chrome的应用程序“高级Rest客户端”模拟了PayPal的post数据: 我想从贝宝那里测试一下,但现在已经足够了。感谢Matt的回答: