PayPal IPN Bad Request 400 Error(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
";
$header .= "Content-Type: application/x-www-form-urlencoded
";
$header .= "Content-Length: " . strlen($req) . "
";
$fp = fsockopen('ssl://www.sandbox.paypal.com', 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.com
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
";
$header .= "Host: www.sandbox.paypal.com
";
这篇关于PayPal IPN 错误请求 400 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PayPal IPN 错误请求 400 错误
基础教程推荐
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
