如何在php中获取application/json类型的内容?

如何在php中获取application/json类型的内容?,php,header,Php,Header,我使用了文件获取内容('php://input)但有时它不起作用。我使用getallheaders()检查了标题,Content Length始终具有内容的大小,但有时file\u get\u contents('php://input)返回空值。请尝试以下操作: $handle = fopen('php://input','r'); $jsonInput = fgets($handle); $decoded = json_decode($jsonInput,true); //$decod

我使用了
文件获取内容('php://input)
但有时它不起作用。我使用
getallheaders()
检查了标题,
Content Length
始终具有内容的大小,但有时
file\u get\u contents('php://input)
返回空值。

请尝试以下操作:

$handle = fopen('php://input','r');
$jsonInput = fgets($handle);
$decoded = json_decode($jsonInput,true);

  //$decoded['tag'] you data

为什么是php://而不是file://.Thank 太感谢你了!我一直认为这是缓存,因为如果我清除它,它会再次工作。无论如何,谢谢!