【发布时间】:2016-05-12 16:33:22
【问题描述】:
如何在 PHP 中使用 curl 发送 Accept Encoding 标头
$data=json_encode($data);
$url = 'url to send';
$headers = array(
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSLVERSION, 4);
$datas = curl_exec($ch);
curl_close($ch);
如何解压响应
【问题讨论】:
-
Content-Type标头从服务器发送到客户端。您正在寻找Accept*标头。 (例如Accept、Accept-Encoding、Acccept-Language)。这告诉服务器你的用户代理支持什么。 -
@Mike 不完全一样,客户端也可以发送
Accept-Encoding标头请求。 -
@PedroLobito 有趣。这与
Accept有何不同? -
14.3 Accept-Encoding- w3.org/Protocols/rfc2616/rfc2616-sec14.html -
@PedroLobito 抱歉,我在这里误读了您的第一条评论。我以为你是说客户可以发送
Content-Type。从上面的链接,The Content-Type entity-header field indicates the media type of the entity-body sent to the recipient,所以我是对的;它只能从服务器发送到客户端。