使用curl时,我发现我所访问的服务器上的行为有所不同,具体取决于我是否通过--compressed
作为一个论点或不。
我已经将 Accept-Encoding 标头设置为 gzip、deflate、sdch:
curl_setopt( $ch, CURLOPT_ENCODING, 'gzip,deflate,sdch' );
我还尝试将编码设置为空字符串:'',因为这意味着支持任何类型的压缩。
但是,如果我通过了--compressed
通过命令行,我返回的内容类型是:gzip
。如果我不进去--compressed
,我返回的内容类型是text/html;charset=UTF-8
使用 PHP 的curl_exec()
,我似乎永远无法让它返回内容类型:gzip。
=====
让我澄清一下我想要实现的目标。当我运行以下命令时:curl -I http://someserver.com --compressed
获取我的内容类型:gzip
运行相同的命令curl -I http://someserver.com
没有--compressed
让我明白
内容类型:text/html;charset=UTF-8
尝试在 PHP 中执行此操作:
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "http://someserver.com" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
// I've tried excluding this line, setting it to gzip, and empty string
curl_setopt( $ch, CURLOPT_ENCODING, '' );
curl_setopt( $ch, CURLOPT_HEADER, 1);
curl_exec( $ch ) );
$content_type = curl_getinfo( $ch, CURLINFO_CONTENT_TYPE );
无论我尝试什么,我都会得到 $content-type =text/html;charset=UTF-8
并不是gzip