这不会获得gzip内容,而是普通内容。如何让file_get_contents使用https发送标题?带有file_get_contents的https标头
$url = 'https://www.google.co.in/';
///Try to fetch compressed content using the file_get_contents function
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en-US,en;q=0.8\r\n" .
"Accept-Encoding: gzip,deflate,sdch\r\n" .
"Accept-Charset:UTF-8,*;q=0.5\r\n"
)
);
$context = stream_context_create($opts);
$zipped_content = file_get_contents($url ,false,$context);
echo $zipped_content;
print_r($http_response_header);
如果URL http://www.yahoo.co.in然后用gzip压缩的内容供应(并确认,它看起来像垃圾)。
但是当使用“https://”时,似乎file_get_contents不会发送指定的标头。
您可能需要使用'fread',而不是二进制安全的。 'file_get_contents'将数据加载为一个字符串......并不是真正想要的。 – 2013-03-22 05:00:48
检查您的浏览器发送给Google的标题并尝试将它们全部发送出去。 – sectus 2013-03-22 05:27:02
@sectus标题都可以 – 2013-03-22 06:50:23