drduh44480 2012-08-12 02:27
浏览 53

500内部服务器错误file_get_contents

If I try and read a sites' source I sometimes get the following (example URL shown):

Warning: file_get_contents(http://www.iwantoneofthose.com/gift-novelty/golf-ball-finding-glasses/10602617.html)
[function.file-get-contents]: failed to open stream: HTTP request failed!
HTTP/1.1 500 Internal Server Error in /home/public_html/pages/scrape.html on line 165

Yet the URL on its own is fine.. why would this happen?

I tried the following workaround suggestion but same result:

$opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0
"));
$context = stream_context_create($opts);
$header = file_get_contents('https://www.example.com',false,$context);

This is baffling me now...

  • 写回答

2条回答 默认 最新

  • duandie5707 2012-08-14 12:34
    关注

    The problem is in your User-Agent header. This worked for me:

    $opts = array('http'=>array('header' => "User-Agent:Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.75 Safari/537.1
    "));
    $context = stream_context_create($opts);
    $header = file_get_contents('http://www.iwantoneofthose.com/gift-novelty/golf-ball-finding-glasses/10602617.html',false,$context);
    
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致