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. python 比较数字大小按从大到小输出

    主要用到的python 的知识点 1:   内置函数max 2:     列表的操作 3:   while 循环 4 :  错误处理 代码如下: #!/usr/bin/python #coding=u ...

  2. virt-install 创建虚拟机

    [root@kvm-server vm]# qemu-img create -f qcow2 centos69b-disk0.qcow2 10G Formatting 'centos69b-disk0 ...

  3. 紫书 例题8-14 UVa 1607 (二分)

    题意非常难理解-- #include<cstdio> #define REP(i, a, b) for(int i = (a); i < (b); i++) using namesp ...

  4. Fiddler(Web/HTTP调试利器)

    简述 Fiddler是一个http协议调试代理工具,它能够记录并检查所有你的电脑和互联网之间的http通讯,设置断点,查看所有的"进出"Fiddler的数据(指cookie.htm ...

  5. UVALive 6084 Happy Camper(数学题)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  6. 本地搭建MongoDB Server

    https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/ Overview Requirements Get Mongo ...

  7. Pocket英语语法---二、指示代词和不定代词是什么

    Pocket英语语法---二.指示代词和不定代词是什么 一.总结 一句话总结: 指示代词:标识人或事物的代词,用来代替前面已提到过的名词 this.these.that.those不定代词:指代不确定 ...

  8. 31.ng-init 指令初始化 AngularJS 应用程序变量。

    转自:https://www.cnblogs.com/best/tag/Angular/ 1. <html> <head> <meta charset="utf ...

  9. ARM嵌入式复习

    第一章 1.嵌入式系统 “以应用为中心,以计算机技术为基础,软硬件可裁剪,适用于应用系统对功能,可靠性,成本,体积,功耗要求严格的专用计算机系统” 根据应用的要求,沿着“体积小,低功耗,高可靠”方向发 ...

  10. Bootstrap-FileInput组件的简单Demo

    官网: https://github.com/kartik-v/bootstrap-fileinput/ http://plugins.krajee.com/file-input   HTML页面: ...