我已经遇到这个问题12小时了,读了大约50篇文章,50个关于此问题的问答,但是我无法解决问题。 我将更加明确地阐述,我希望其他人也能得到解决方案。
问题:我在namech****拥有一个托管账户,并且有一个本地服务器。 在那里使用Linux系统,在我的电脑上使用Xampp Windows系统,但只在我的本地服务器上工作。
test.php:
<?php
$data = json_decode(file_get_contents("php://input"), true);
var_dump($data);
?>
POST请求是:
POST /test.php HTTP/1.1
Host: myweb.io
Content-Type: application/json
Content-Length: 77
{
"test": "product/created",
"other": "https://google.com/"
}
我使用REQBIN来测试POST请求。
以下是我的主机返回的响应:
HTTP/1.1 200 OK
Date: Sun, 03 May 2020 17:04:33 GMT
Server: Apache
X-Powered-By: PHP/7.4.5
Content-Encoding: gzip
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
NULL
使用XAMPP在我的本地环境中这是正确的响应
HTTP/1.1 200 OK
Date: Sun, 03 May 2020 17:15:19 GMT
Server: Apache/2.4.41 (Win64) OpenSSL/1.1.1c PHP/7.4.3
X-Powered-By: PHP/7.4.3
Content-Length: 94
Content-Type: text/html; charset=UTF-8
Array
(
[test] => product/created
[other] => https://google.com/
)
我尝试过的方法:
- 将allow_url_fopen设置为1或0。
- 降级PHP版本(尝试了7.1、2、3、4)。
- 卸载SSL证书
- 在PHP.INI中进行了许多更改
- 移除htaccess文件
- 删除某些php模块/扩展 更新:
- 该文件是独立的,检查了函数只执行了一次
- 检查是否存在重定向。(Htaccess、cPanel设置)
var_dump(file_get_contents("php://input"));
会打印什么? - Álvaro González