gpt4 book ai didi

php - 如何在 PHP 中使用 curl 发送接受编码 header

转载 作者:行者123 更新时间:2023-12-03 15:58:34 25 4
gpt4 key购买 nike

如何在 PHP 中使用 curl 发送 Accept Encoding header

  $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);

如何解压响应

最佳答案

您可以使用 CURLOPT_ENCODING :

curl_setopt($ch, CURLOPT_ENCODING, "");

The contents of the "Accept-Encoding: " header. This enables decoding of the response. Supported encodings are "identity", "deflate", and "gzip". If an empty string, "", is set, a header containing all supported encoding types is sent.



http://php.net/manual/en/function.curl-setopt.php

或者,您可以发送 header :
$headers = array(
'Accept: text/plain'
);

强制响应 txt

关于php - 如何在 PHP 中使用 curl 发送接受编码 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37192693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com