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


How to get the contents of application/json type in php?

我使用file_get_contents('php://input'),但有时它不会工作。我使用getallheaders()检查了标题,Content-Length始终是内容的大小,但有时file_get_contents('php://input')返回null。

Try This:

$handle = fopen('php://input','r');
$jsonInput = fgets($handle);
$decoded = json_decode($jsonInput,true);
  //$decoded['tag'] you data