PayPal 验证失败并显示无效
我正在尝试设置 PayPal Ipn,但某些订单验证失败。我发现如果用户名包含一些非标准字母,例如 &last_name=Montalvo Agüera
,则会失败 我需要更改编码吗?
var request = "cmd=_notify-validate&.......";
const string strLive = "https://www.paypal.com/cgi-bin/webscr";
var req = (HttpWebRequest)WebRequest.Create(strLive);
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = request.Length;
var streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
streamOut.Write(request);
streamOut.Close();
var streamIn = new StreamReader(req.GetResponse().GetResponseStream());
var strResponse = streamIn.ReadToEnd();
streamIn.Close();
Response.Write(strResponse);
I am trying to set up PayPal Ipn and it is failing on some orders verification. I found that it fails if users name has some non standard letters like &last_name=Montalvo Agüera
Do I need to change encoding?
var request = "cmd=_notify-validate&.......";
const string strLive = "https://www.paypal.com/cgi-bin/webscr";
var req = (HttpWebRequest)WebRequest.Create(strLive);
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = request.Length;
var streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
streamOut.Write(request);
streamOut.Close();
var streamIn = new StreamReader(req.GetResponse().GetResponseStream());
var strResponse = streamIn.ReadToEnd();
streamIn.Close();
Response.Write(strResponse);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以这样尝试:
如果还是不行尝试将编码改为UTF8
You can try it like this:
If it still doesn't work try to change the encoding to UTF8
您需要对参数进行 url 编码。这就是
req.ContentType = "application/x-www-form-urlencoded";
行的含义。这是您向 HTTP 服务器做出的承诺(在本例中是 PayPal 的 www.paypal.com)。我们承诺您发送的任何数据都将进行 url 编码。这意味着您必须转义任何特殊字符。这包括?
和&
和%
等字符以及ü
等字符。要对名称进行 url 编码,您需要使用 url 编码的名称构建请求:
You need to url-encode the parameters. That's what the line
req.ContentType = "application/x-www-form-urlencoded";
means. It's you making a promise to the HTTP server (in this case, PayPal's www.paypal.com). The promise is that any data you send will be url-encoded. This means you have to escape any special characters. This includes characters like?
and&
and%
and also characters likeü
.To url-encode the name, you need to build the request with the url-encoded name: