使用curl时,我看到服务器上的行为有所不同,具体取决于我是否通过--compressed
作为参数。有没有办法通过 - 压缩到PHP的curl_setopt()?
我已经设置Accept-Encoding头为gzip,放气,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
“Content-Type”标头绝对没问题。它在我看来通过你实际上对'Content-Encoding'头部感兴趣(对于'Content-Encoding:gzip')。 – salathe