可能是重复问题:
如何在php中获取POST的主体内容?
我正在接收一个包含JSON的POST,但问题是当我接收到时$_POST为空。为了测试是否接收到POST,我创建了一个文件来包含$_POST,$_GET和$_REQUEST,它们都为空。
发送请求的客户端正在执行以下操作:
$itemJson = '{
"id": 00,
"value": "ok"
}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: '. strlen($itemJson))
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $itemJson);
curl_close($ch);
坦白说,我不明白我是如何获取这些数据的,因为没有设置任何参数。
有什么想法吗?