failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

一、总结

一句话总结:这里出现的问题是我在博客园删除了一篇文章,时间太短,所以博客园还没有更新,所以当我用删除的那篇文章的链接访问博客园的时候,就出现了这个错误提示:这是是真的是因为文件已经被删除了。

file_get_contents(https://www.cnblogs.com/Renyi-Fan/p/9620120.html): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

1、php如何伪造user_agent(伪造user agent的代码的位置)?

file_get_contents伪造user_agent 方法如下:
ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;)');

curl伪造user_agent的方法:
curl_setopt($c, CURLOPT_USERAGENT,'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;)');

ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;)');
$html=file_get_contents($url);

2、如何解决failed-to-open-stream:-HTTP-request-failed?

有人说在php.ini中,有这样两个选项:allow_url_fopen =on(表示可以通过url打开远程文件),user_agent="PHP"(表示通过哪种脚本访问网络,默认前面有个 " ; " 去掉即可。)重启服务器。

二、完美解决failed-to-open-stream:-HTTP-request-failed

当使用php5自带的file_get_contents方法来获取远程文件的时候,有时候会出现file_get_contents(): failed to open stream: HTTP request failed!这个警告信息。

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)”

=============================================================================================

方法二

file_get_contents 和 curl 这俩强悍的函数,在远程抓取时候相当有用处.不过一些网站会根据来访ip是否携带user_agent来判断是正常的浏览器客户端还是机器.所以,我们的任务就是给他们伪造user_agent.
file_get_contents伪造user_agent 方法如下:
ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;)');

curl伪造user_agent的方法:
curl_setopt($c, CURLOPT_USERAGENT,'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;)');

参考:完美解决failed-to-open-stream:-HTTP-request-failed!_翁雪杰(WAP-6131)_新浪博客
http://blog.sina.com.cn/s/blog_700e11ff0101228l.html

 

failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found的更多相关文章

  1. 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 ...

  2. 完美解决failed to open stream: HTTP request failed!(file_get_contents引起的)

    当使用php5自带的file_get_contents方法来获取远程文件的时候,有时候会出现file_get_contents(): failed to open stream: HTTP reque ...

  3. failed to open stream: HTTP request failed! HTTP/1.1 505 HTTP Version Not Supported

    PHP模拟GET请求支付宝退款链接(未用sdk  自己拼接的请求链接与参数); 起初用file_get_contents();就报错 :failed to open stream: HTTP requ ...

  4. file_get_contents failed to open stream: HTTP request failed(一个字符决定成败)

    file_get_contents 开始成功了.后来不知怎么的就报错,调试半天没发现什么问题. 结果.里面多了一个"空格"就报错.去掉空格就好了,你们仔细找找吧.

  5. failed to open stream :HTTP request failed 解决方法

    用curl抓取,不要用file_get_contents(); 前者比后者效率高一点

  6. file_get_contents HTTP request failed! Internal Server Error

    使用file_get_contents报错 Severity: WarningMessage: file_get_contents(http://geetest.com:8000/select?gid ...

  7. 上传文件出错:org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly

    最近做一个web项目中有上传文件的功能,已经写出并在本地和部署到服务器上测试了好几个文件上传都没问题(我用的是tomcat).后来又上传了一个700多K的文件(前边的都是不足600K的,并且这个wor ...

  8. file_put_contents 错误:failed to open stream: Invalid argument 一种原因

    今天在测试nilcms系统的时候,出现了一个报错,导致缓存无法更新: file_put_contents(C:\UPUPW_AP5.4\vhosts\d.tv\NilCMS_APP\include_r ...

  9. Warning: file_put_contents(data.txt): failed to open stream: Permission denied in /Library/WebServer/Documents/test.php on line 22

    最近在学习PHP 在保存文件的时候报Warning: file_put_contents(data.txt): failed to open stream: Permission denied in ...

随机推荐

  1. k8s使用cephfs

    以下为ceph集群操作内容 cephfs 将cephfs挂载到一台服务器 /mnt/cephf . 创建目录 mkdir -p /mnt/cephf/k8s/staff-nginx/{conf,dat ...

  2. ubuntu 16.04 安装KVM-多系统

    为了使用QQ 只能再跑一个Windows了

  3. vue-cli#2.0项目结构分析

    项目结构 build 构建工具相关的目录 config 配置目录 dist 通过工具打包生成的最终需要上线的目录 node_modules 存放本地开发所有的依赖包的目录 src 源码目录 stati ...

  4. python 中进制转换及format(),int()函数用法

    python中数值型变量好像只能是十进制形式表示,其他类型变量只能以字符串形式存在,可以通过format函数将int类型变量转换成其他进制字符串,如下所示: v_code=15 # 2进制 x=for ...

  5. jquery及相关兼容插件的版本搭配

    1.jquery1.11.0 + jquery.validate.1.9.0.js + jquery.ui.1.10.4.js

  6. js 判断是否滚动到底部

    $(window).scroll(function(){ var scrollTop = $(this).scrollTop(); //scrollTop() 方法返回或设置匹配元素的滚动条的垂直位置 ...

  7. [React] React.PureComponent

    React.PureComponent is similar to React.Component. The difference between them is that React.Compone ...

  8. WIZnet相关产品介绍

    WIZnet  自1998年在韩国创立以来,一致专注研发全硬件TCP/IP协议栈芯片.同一时候开发设计相关网络模块和无线产品,同一时候 WIZnet 鼓舞开源硬件.相关开源硬件产品也已层出不断. 主要 ...

  9. html-上左右布局方式---ShinePans

    文件包括 main.html  top.html  left.html  childhood.html  moonsong.html  herethesea.html 主要布局效果: 代码: main ...

  10. IIS Express加入MIME映射

    近期在用Grid Report做Web报表的时候,碰到一件非常挠头的事. 本地用VS2010写的代码,调试的时候Web报表无法显示,用24.248server上VS2013相同仍是无法显示.最后把项目 ...