failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
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的更多相关文章
- 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 to open stream: HTTP request failed!(file_get_contents引起的)
当使用php5自带的file_get_contents方法来获取远程文件的时候,有时候会出现file_get_contents(): failed to open stream: HTTP reque ...
- 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 ...
- file_get_contents failed to open stream: HTTP request failed(一个字符决定成败)
file_get_contents 开始成功了.后来不知怎么的就报错,调试半天没发现什么问题. 结果.里面多了一个"空格"就报错.去掉空格就好了,你们仔细找找吧.
- failed to open stream :HTTP request failed 解决方法
用curl抓取,不要用file_get_contents(); 前者比后者效率高一点
- file_get_contents HTTP request failed! Internal Server Error
使用file_get_contents报错 Severity: WarningMessage: file_get_contents(http://geetest.com:8000/select?gid ...
- 上传文件出错:org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly
最近做一个web项目中有上传文件的功能,已经写出并在本地和部署到服务器上测试了好几个文件上传都没问题(我用的是tomcat).后来又上传了一个700多K的文件(前边的都是不足600K的,并且这个wor ...
- file_put_contents 错误:failed to open stream: Invalid argument 一种原因
今天在测试nilcms系统的时候,出现了一个报错,导致缓存无法更新: file_put_contents(C:\UPUPW_AP5.4\vhosts\d.tv\NilCMS_APP\include_r ...
- 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 ...
随机推荐
- 紫书 例题 10-3 UVa 10375 (唯一分解定理)
这道题感觉非常的秀 因为结果会很大,所以就质因数分解分开来算 非常的巧妙! #include<cstdio> #include<vector> #include<cstr ...
- 紫书 习题 11-16 UVa 1669(树形dp)
想了很久, 以为是网络流最大流, 后来建模建不出来, 无奈. 后来看了 https://blog.csdn.net/hao_zong_yin/article/details/79441180 感觉思路 ...
- ocrsearch的横屏转竖屏的解决方案
//这是其中解决预览图的一部分(坑了好久的)@Override public void onPreviewFrame(byte[] data, Camera camera) { Size previe ...
- 怎样在windows7上使用snmp命令
原文地址:http://wenboxz.com/archives/window7-use-snmp-command.html/
- 利用艺术家的整数ID映射将标签转换为向量
<strong><span style="font-size:18px;">/*** * @author YangXin * @info Mapper选择艺 ...
- IOS开发的哪些异常之异常断点
从Android开发的异常报错到IOS的异常闪退,经历了不一样的处理过程.对于IOS的异常报错刚開始总是非常茫然,永远仅仅告诉你有异常.然后就跳到main.m文件,却不曾我告诉她在那出现.真是吊人胃口 ...
- jsp学习-分页功能的实现
<%@ page contentType="text/html;charset=utf-8" pageEncoding="utf-8"%> < ...
- Getting Started with MongoDB (C# Edition)
https://docs.mongodb.com/getting-started/csharp/ 概览 Welcome to the Getting Started with MongoDB guid ...
- hdoj--2098--分拆素数和(水题)
分拆素数和 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- [NOIP2015模拟10.22] 最大子矩阵 解题报告(单调栈)
Description 我们将矩阵A中位于第i行第j列的元素记作A[i,j].一个矩阵A是酷的仅当它满足下面的条件: A[1,1]+A[r,s]<=A[1,s]+A[r,1](r,s ...