首页 > 代码库 > php file_get_contents失败[function.file-get-contents]: failed to open stream: HTTP request failed!解决

php file_get_contents失败[function.file-get-contents]: failed to open stream: HTTP request failed!解决

在使用file_get_contents方法来获取远程文件时会出现

[function.file-get-contents]: failed to open stream: HTTP request failed!

错误

解决方法是:修改php.ini 中的allow_url_fopen = On 这样可以解决部分人的问题,

完美的解决方案还得修改user_agent="PHP"  ,将参数改为Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)

user_agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"

模拟浏览器就可以了;

php file_get_contents失败[function.file-get-contents]: failed to open stream: HTTP request failed!解决