简体   繁体   English

从 POST 请求 POSTMAN 的正文中检索 JSON

[英]Retrive JSON from body in a POST request POSTMAN

I have a problem receiving the body of a POST call from Postman, but it could be from other channels as well.我在接收来自 Postman 的 POST 调用的主体时遇到问题,但它也可能来自其他渠道。 The Headers I recover them without problems but the JSON in the body always keeps returning NULL or an empty array.我恢复它们的标题没有问题,但正文中的 JSON 总是不断返回 NULL 或空数组。

Can anyone help me?谁能帮我? Thank you alby696谢谢alby696

$payload = file_get_contents('php://input');
$receivedHeaders = getRequestHeaders();
$myPostArgs = filter_input_array(INPUT_POST);

var_dump($_POST);

var_dump(json_decode($payload,true));

var_dump($myPostArgs);

邮差

I answer myself, I found the problem of the null answer.我自己回答,我发现了 null 答案的问题。

In the headers I had disabled Content-Length.在标题中,我禁用了 Content-Length。
Re-enabled, I now see the array populated in the response.重新启用后,我现在看到响应中填充了数组。
The code used in the php is php 中使用的代码是

$test = json_decode(file_get_contents("php://input"), true);
var_dump($test);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM