如果我尝试阅读网站的源代码,有时会得到以下信息(显示的示例 URL):
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
然而,URL 本身就很好.. 为什么会发生这种情况?
我尝试了以下解决方法建议,但结果相同:
$opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n"));
$context = stream_context_create($opts);
$header = file_get_contents('https://www.example.com',false,$context);
这让我现在很困惑...