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

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

我用过file_get_contents('php://input'),但有时它不起作用。我使用 getallheaders() 检查了 headers 并且 Content-Length 始终具有内容的大小,但有时 file_get_contents('php://input') returns null.

试试这个:

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

  //$decoded['tag'] you data