doupeng8419 2013-03-22 04:31
浏览 33
已采纳

带有file_get_contents的https标头

This does not get gzipped content, but plain content. How to make file_get_contents send headers with 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
" .
                "Accept-Encoding: gzip,deflate,sdch
" .
                "Accept-Charset:UTF-8,*;q=0.5
"
)
);

$context = stream_context_create($opts);
$zipped_content = file_get_contents($url ,false,$context);

echo $zipped_content;

print_r($http_response_header);

If the url is http://www.yahoo.co.in then the gzipped content is served (and to confirm, it appears like rubbish).

But when using "https://" it seems that file_get_contents does not send the headers specified.

  • 写回答

2条回答 默认 最新

  • douzhang7728 2013-03-22 07:35
    关注

    Header are no OK... Add User-agent and it will be fine.

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

    Why? Google decides.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 代码本地运行正常,但是TOMCAT部署时闪退
  • ¥15 关于#python#的问题
  • ¥15 主机可以ping通路由器但是连不上网怎么办
  • ¥15 数据库一张以时间排好序的表中,找出多次相邻的那些行
  • ¥50 关于DynamoRIO处理多线程程序时候的问题
  • ¥15 kubeadm部署k8s出错
  • ¥15 Abaqus打不开cae文件怎么办?
  • ¥20 双系统开机引导中windows系统消失问题?
  • ¥15 小程序准备上线,软件开发公司需要提供哪些资料给甲方
  • ¥15 关于生产日期批次退货退款,库存回退的问题