Php POST URL编码时接收JSON响应
我想在通过POST提交URL编码的请求后接收并解码JSON响应。Php POST URL编码时接收JSON响应,php,json,post,Php,Json,Post,我想在通过POST提交URL编码的请求后接收并解码JSON响应。 但我在下面运行后得到的($content)是乱码字符。 我相信服务器返回的值是正确的(我通过hurl.it进行了检查) PHP代码如下 $target_url = "http://examples.com/send";] $headers = array( 'Host: examples.com', 'Content-Type: application/x-www-form-urlencoded; charset=
但我在下面运行后得到的($content)是乱码字符。
我相信服务器返回的值是正确的(我通过hurl.it进行了检查) PHP代码如下
$target_url = "http://examples.com/send";]
$headers = array(
'Host: examples.com',
'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
'Accept-Language: en-us',
'Accept-Encoding: gzip, deflate',
'User-Agent: Appcelerator Titanium/3.5.0',
);
$data = array(
'id' => 'hogehoge',
'command' => 'renew'
);
$options = array('http' => array(
'method' => 'POST',
'content' => http_build_query($data),
'header' => implode("\r\n", $headers),
));
$contents = file_get_contents($target_url, false, stream_context_create($options));
echo $contents;
响应的标题是
Connection: keep-alive
Content-Encoding: gzip
Content-Length: 32
Content-Type: application/json; charset=utf-8
Date: ***** GMT
Server: Apache
Vary: Accept-Encoding,User-Agent
当我回显$contents时,我得到了
�ォV*J-.ヘ)Qイ2ャワゥp0
虽然应该是
{"result":1}
提前谢谢
加:
当我
var\u dump(json\u decode($contents))
时,我得到NULL
作为响应,服务器通知您它正在发送压缩内容,您必须解压缩它
Content-encoding: gzip
您可以使用gzdecode()解压gzip
echo gzdecode($content);
作为响应,服务器通知您它正在发送压缩的内容,您必须解压缩它
Content-encoding: gzip
您可以使用gzdecode()解压gzip
echo gzdecode($content);
解压缩内容:
echo gzdecode($contents);
解压缩内容:
echo gzdecode($contents);
您正在接收一个gzip字符串,该字符串由标题
Content Encoding:gzip
指向
您可以使用php或js解压它
您正在接收一个gzip字符串,该字符串由标题
Content Encoding:gzip
指向
您可以使用php或js解压它
gzip
您必须解压缩它。注意:内容编码:gzip
。您得到了json,它只是gzip。$target\u url=”http://examples.com/send";]代码>我想它一定是$target\u url=”http://examples.com/send";
可能是输入错误?或者删除'Accept-Encoding:gzip,deflate'
gzip
您必须将其解压缩。注意:内容编码:gzip
。您得到了json,它只是gzip。$target\u url=”http://examples.com/send";]代码>我想它一定是$target\u url=”http://examples.com/send";
可能是输入错误?或者删除'Accept-Encoding:gzip,deflate'
刚刚找到这个刚刚找到这个