Php 包含文件内容的https标头

Php 包含文件内容的https标头,php,Php,这不会得到gzip内容,而是普通内容。如何使用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=

这不会得到gzip内容,而是普通内容。如何使用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是空的,那么就提供gzip内容(并且要确认,它看起来像垃圾)

但是当使用“https://”时,文件内容似乎不发送指定的标题。

试试这个

 $url = "https://www.google.co.in/";   
  $ch = curl_init();    
  curl_setopt($ch,CURLOPT_URL,$url);   
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);   
  curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);    
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip'));   
  $contents = curl_exec($ch);   
  curl_close($ch);

标题不正确。。。添加用户代理就可以了

"User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0 FirePHP/0.4\r\n".

为什么??谷歌决定。

您可能需要使用
fread
,这是二进制安全的<代码>文件\u获取\u内容将数据作为字符串加载。。。不是你想要的。检查你的浏览器发送到谷歌的标题,并尝试发送它们。@sectus标题都可以。我需要gzip内容,curl代码将获取我不需要的页面的最终html内容。