php错误提示failed to open stream: HTTP request failed!的完美解决方法
2011-06-06 15:10
2291 查看
google或者baidu一下,好多这样的问题,解决的方法都是修改php.ini,把allow_url_fopen给启用,改成 allow_url_fopen = On
这样做可以解决某些人的问题,有人说在php.ini中,有这样两个选项:allow_url_fopen =on(表示可以通过url打开远程文件),user_agent="PHP"(表示通过哪种脚本访问网络,默认前面有个 " ; " 去掉即可。)重启服务器。
但是有些还是会有这个警告信息,想用完美的解决还差一步,还得设置php.ini里面的user_agent,php默认的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)”
在工作中遇到这个问题,后完美解决,故分享给大家。
我批量抓取chemblink的结构式发现循环后有部分图片无法显示,而远程文件是存在的。
抓取远程文件的时候出现类似Warning: readfile(//www.jb51.net/logo.gif) [function.readfile]: failed to open stream: HTTP request failed! 这样的警告信息,我使用的是
复制代码 代码如下:
ob_start();
readfile("//www.jb51.net/logo.gif");
$img = ob_get_contents();
ob_end_clean();
这样在运行中会时不时的出现上述错误,我也换过file_get_contents等其他函数都没用用,在网上查阅后发现用CURL方法抓取不会出错
现在比较流行使用curl
复制代码 代码如下:
<?php
$url = "http://s.jb51.net";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
$dxycontent = curl_exec($ch);
echo $dxycontent;
?>
这样做可以解决某些人的问题,有人说在php.ini中,有这样两个选项:allow_url_fopen =on(表示可以通过url打开远程文件),user_agent="PHP"(表示通过哪种脚本访问网络,默认前面有个 " ; " 去掉即可。)重启服务器。
但是有些还是会有这个警告信息,想用完美的解决还差一步,还得设置php.ini里面的user_agent,php默认的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)”
在工作中遇到这个问题,后完美解决,故分享给大家。
我批量抓取chemblink的结构式发现循环后有部分图片无法显示,而远程文件是存在的。
抓取远程文件的时候出现类似Warning: readfile(//www.jb51.net/logo.gif) [function.readfile]: failed to open stream: HTTP request failed! 这样的警告信息,我使用的是
复制代码 代码如下:
ob_start();
readfile("//www.jb51.net/logo.gif");
$img = ob_get_contents();
ob_end_clean();
这样在运行中会时不时的出现上述错误,我也换过file_get_contents等其他函数都没用用,在网上查阅后发现用CURL方法抓取不会出错
现在比较流行使用curl
复制代码 代码如下:
<?php
$url = "http://s.jb51.net";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
$dxycontent = curl_exec($ch);
echo $dxycontent;
?>
您可能感兴趣的文章:
相关文章推荐
- php错误提示failed to open stream: HTTP request failed!的完美解决方法
- php错误提示failed to open stream: HTTP request failed!
- 完美解决failed to open stream: HTTP request failed!(file_get_contents引起的)
- 【分享】完美解决failed to open stream: HTTP request failed!
- 完美解决failed to open stream: HTTP request failed!
- PHP解决[function.file-get-contents]: failed to open stream: HTTP request failed!
- 完美解决failed to open stream: HTTP request failed!(file_get_contents引起的)
- 完美解决failed to open stream: HTTP request failed!(file_get_contents引起的)
- php错误:failed to open stream: HTTP request failed!
- [乐意黎原创]PHP 写入文件时抛failed to open stream:Permission denied in 错误的解决方法
- 完美解决failed to open stream: HTTP request failed!
- 完美解决failed to open stream: HTTP request failed!(file_get_contents引起的)
- 完美解决failed to open stream: HTTP request failed!
- 完美解决failed to open stream: HTTP request failed!(file_get_contents引起的)
- php file_get_contents失败[function.file-get-contents]: failed to open stream: HTTP request failed!解决
- 解决failed-to-open-stream:-HTTP-request-failed!
- PHP问题 —— failed to open stream: HTTP request faile
- 解决failed to open stream: HTTP request failed!
- php提示Failed to write session data错误的解决方法