file_get_contents HTTP request failed! Internal Server Error

使用file_get_contents报错

Severity: Warning
Message: file_get_contents(http://geetest.com:8000/select?gid=bf59a3fe652ece81dfb179219ce5b46e&date=2013-08-09) [function.file-get-contents]: failed to open stream: HTTP request failed! Internal Server Error

遇到这种情况不要慌,我们只要将php默认的user_agent改成Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; GreenBrowser)进来模拟浏览器即可。

修改方法:

PHP伪造user_agent

   ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; GreenBrowser)');

伪造自后还是不行

  $context = stream_context_create(array('http'=>array('ignore_errors'=>true)));

  $nos = file_get_contents($url, FALSE, $context);

完整栗子:

ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; GreenBrowser)');
$context = stream_context_create(array('http'=>array('ignore_errors'=>true)));
file_get_contents($url, FALSE, $context);

 

原文地址:https://www.cnblogs.com/54sen/p/6732145.html