我在过去的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/
)
我尝试过的事情:
请尝试以下代码:
// get decompressed POST request
$decomprReq = gzdecode($comprReq);
// decode to json
$jsonData = json_decode($decomprReq, true);