I'm writing a script that is registered as an endpoint for a webhook. I know that it's successfully registered because I'm writing the header of every request to my server logs. Here's a sample:
Content-Type: text/xml; charset=UTF-8
User-Agent: Jakarta Commons-HttpClient/3.1
Host: =={obfuscated}==
Content-Length: 1918
我注册的API正在将一个JSON对象发布到我的脚本中,我想用PHP解析这个对象.从请求头中可以看到,有一个漂亮的大而胖的JSON对象正在等待解析.这似乎很简单,但事实并非如此.
起初,我try 使用$_POST['json']
或只使用$_POST
,但由于数据不在数组中,我真的不确定如何以这种方式访问它.
我试过用file_get_contents('php://input')
和fopen('php://input', 'r')
,加json_decode()
和不加json_decode()
都不行.我不能使用http_get_request_body()
,因为我使用的服务器没有PECL,这不在我的控制范围之内.
Are there any other ways to interact with the POST-ed JSON object that I'm missing? Thanks!