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条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧