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

After chopping hands, the fraud call came before the express delivery was received. How to improve the privacy and security of e-commerce>>>

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

1、 Summary

In a word: the problem here is that I deleted an article in the blog Garden for a short time, so the blog Garden has not been updated, so when I visited the blog Garden with the link of the deleted article, this error prompt appeared: This is true because the file has been deleted

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. How PHP forges user_ Agent (forge the location of user agent’s code)

file_ get_ Contents user_ The agent method is as follows:
ini_ set(‘user_ agent’,’Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; . NET CLR 2.0.50727;)’);

Curl forgery user_ Method of 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. How to solve the problem of failed to open- stream:-HTTP-request-failed ?

Some people say that in php.ini, there are two options: allow_ url_ Fopen = on (indicates that the remote file can be opened through URL), user_ Agent = “PHP” (indicates which script is used to access the network. By default, there is a “;” Remove it.) Restart the server

2、 Perfect solution to failed to open- stream:-HTTP-request-failed

When using PHP5’s own file_ get_ When the contents method is used to get remote files, sometimes the file will appear_ get_ contents(): failed to open stream: HTTP request failed! This is a warning message

Google or Baidu, a lot of such problems, the solution is to modify PHP. Ini, allow_ url_ Fopen is enabled and changed to allow_ url_ fopen = On

This can solve some people’s problems. Some people say that in php.ini, there are two options: allow_ url_ Fopen = on (indicates that the remote file can be opened through URL), user_ Agent = “PHP” (indicates which script is used to access the network. By default, there is a “;” Remove it.) Restart the server

However, some of them still have this warning message. If you want to solve it perfectly, you still need to set the user in php.ini_ Agent, PHP’s default user_ The agent is PHP, we changed it to Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) to simulate the browser

user_ agent=”Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)”

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

Method 2

file_ get_ Content and curl are two powerful functions, which are quite useful in remote crawling. However, some websites will carry users according to the visiting IP_ Agent to determine whether it is a normal browser client or a machine. Therefore, our task is to forge users for them_ agent.
file_ get_ Contents user_ The agent method is as follows:
ini_ set(‘user_ agent’,’Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; . NET CLR 2.0.50727;)’);

Curl forgery user_ Method of agent:
curl_ setopt($c, CURLOPT_ USERAGENT,’Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; . NET CLR 2.0.50727;)’);

Reference: the perfect solution to failed to open- stream:-HTTP-request-failed!_ Weng Xuejie (wap-6131)_ Sina blog
http://blog.sina.com.cn/s/blog_ 700e11ff0101228l.html

Similar Posts: