PayPal IPN错误请求400错误

编程入门 行业动态 更新时间:2024-10-09 11:18:49
本文介绍了PayPal IPN错误请求400错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用PayPal IPN时,我不断收到错误400.

Using the PayPal IPN, I keep getting an error 400.

我一直在使脚本向$res的电子邮件发送给我,以查看响应是什么,并且位于while (!feof($fp)) {}循环内.我总是最终得到错误:HTTP/1.0 400 Bad Request

I have been making the script send me emails of $res to see what the response is, inside of the while (!feof($fp)) {} loop. I always end up getting the error: HTTP/1.0 400 Bad Request

我总共回来了:

HTTP/1.0 400 Bad Request ​Connection: close Server: BigIP Content-Length: 19 ​Invalid Host Header

这之后的最后一行只是空白.这是我的代码,我尝试过更改工作量,但是没有任何效果.

​The last line after this is just blank. Here is my code, I have tried changing loads of things but nothing works.

$req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}', $value);// IPN fix $req .= "&$key=$value"; } // post back to PayPal system to validate $header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen('ssl://www.sandbox.paypal', 443, $errno, $errstr, 30); if (!$fp) { // HTTP ERROR } else { fputs($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { //ADD TO DB } else if (strcmp ($res, "INVALID") == 0) { // PAYMENT INVALID & INVESTIGATE MANUALY! // E-mail admin or alert user } } fclose ($fp); }

我添加了一行,这是发送前的标题:

I have added a line, this is the header before it is sent:

Host: www.sandbox.paypal POST /cgi-bin/webscr HTTP/1.0 Content-Type: application/x-www-form-urlencoded Content-Length: 1096

推荐答案

由于您是自己打开套接字的,而不是使用curl这样的HTTP库,因此需要设置适当的HTTP协议版本并添加 HTTP主机标头自己位于POST行下方.

Since you're opening the socket yourself, rather than using an HTTP library such as curl, you need to set the proper HTTP Protocol version and add the HTTP Host header yourself just below the POST line.

$header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; $header .= "Host: www.sandbox.paypal\r\n";

更多推荐

PayPal IPN错误请求400错误

本文发布于:2023-10-10 17:57:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479323.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   PayPal   IPN

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!