file_get_contents('php:// input')无效。空-NULL

问题描述 投票:1回答:1

我在过去的12个小时中一直遇到这个问题,我在这里阅读了约50篇文章,有50个问题,我无法解决。我会更加精确,我也希望其他人也能找到解决方案。

问题:我在namech ****中有一个托管帐户,还有一个本地服务器。这里有Linux,这里有Xampp Windows,这仅在我的本地服务器上有效。

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设置)
php file-get-contents
1个回答
0
投票

请尝试以下代码:

// get decompressed POST request
$decomprReq = gzdecode($comprReq);

// decode to json
$jsonData = json_decode($decomprReq, true);
© www.soinside.com 2019 - 2024. All rights reserved.