file_get_contents('php://input') 不起作用。空 - 空



在过去的12个小时里,我遇到了这个问题,我读了大约50篇文章,这里有50个问题,我无法解决。我会更准确地说,我希望其他人也能得到解决方案。

问题:我在namech***有一个托管帐户,还有一个本地服务器。Linux在这里,XamppWindows在这里,这只适用于我的本地服务器。

test.php:
<?php    
$data = json_decode(file_get_contents("php://input"), true);
var_dump($data);
?>

张贴请求是:

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设置(

我遇到了同样的问题;显然,HTTP重定向(例如301到https(禁止数据被重定向。

请确保没有重定向。

信不信由你:

更改:重写规则^/%1[NC,L,R]

重写规则^%1[NC,L,R]

然后返回

重写规则^/%1[NC,L,R]

同样重写规则^(.*?(/?$/$1.php[NC,L]

重写规则^(.*?(/?$$1.php[NC,L]

然后返回

重写规则^(.*?(/?$/$1.php[NC,L]

似乎解决了问题!

我修复了它,不知道如何修复,但我认为解决方案是:完全删除我的htaccess,没有重定向(http到https(。不要用reqbin测试,用php纯代码或PostMan测试。

我也遇到了这个问题,我意识到我的地址是http://而不是https://

现在我有了file_get_contents("php://input")

我希望这能解决你的问题。

最新更新