Home > Backend Development > PHP Tutorial > PHP:file_get_contents failed to open stream: HTTP request failed

PHP:file_get_contents failed to open stream: HTTP request failed

WBOY
Release: 2016-06-06 20:46:15
Original
2213 people have browsed it

新建一个test.php

<code><?php echo file_get_contents("http://test1.xiaoci.com/create.php");
?>
</code>
Copy after login
Copy after login

然后访问test.php,结果报错如下:

Warning: file_get_contents(http://test1.xiaoci.com/create.php) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in J:\wamp\www\long\wwwroot\mytools\test\test1.php on line 3

PHP:file_get_contents failed to open stream: HTTP request failed

注意:http://test1.xiaoci.com是我在本地搭建的一个虚拟主机
在本地搭建的一个虚拟主机,配置信息如下:
http-vhost.conf

<code><virtualhost>
    DocumentRoot "d:/wamp/www/"
    ServerName test1.xiaoci.com 
</virtualhost>
</code>
Copy after login
Copy after login

hosts

<code>127.0.0.1       test1.com
127.0.0.1               test1.xiaoci.com
</code>
Copy after login
Copy after login

并且设置了404返回到index.php,所以当手动从浏览器中打开http://test1.xiaoci.com/create.php网址的时候,由于create.php是不存在的页面,所以会转到index.php,然后在index.php中进行处理。
手动打开("http://test1.xiaoci.com/create.php")情况:可以正常访问
使用file_get_contents("http://test1.xiaoci.com/create.php"):报404错误

回复内容:

新建一个test.php

<code><?php echo file_get_contents("http://test1.xiaoci.com/create.php");
?>
</code>
Copy after login
Copy after login

然后访问test.php,结果报错如下:

Warning: file_get_contents(http://test1.xiaoci.com/create.php) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in J:\wamp\www\long\wwwroot\mytools\test\test1.php on line 3

PHP:file_get_contents failed to open stream: HTTP request failed

注意:http://test1.xiaoci.com是我在本地搭建的一个虚拟主机
在本地搭建的一个虚拟主机,配置信息如下:
http-vhost.conf

<code><virtualhost>
    DocumentRoot "d:/wamp/www/"
    ServerName test1.xiaoci.com 
</virtualhost>
</code>
Copy after login
Copy after login

hosts

<code>127.0.0.1       test1.com
127.0.0.1               test1.xiaoci.com
</code>
Copy after login
Copy after login

并且设置了404返回到index.php,所以当手动从浏览器中打开http://test1.xiaoci.com/create.php网址的时候,由于create.php是不存在的页面,所以会转到index.php,然后在index.php中进行处理。
手动打开("http://test1.xiaoci.com/create.php")情况:可以正常访问
使用file_get_contents("http://test1.xiaoci.com/create.php"):报404错误

host难道不应该是

127.0.0.1 test1.xiaoci.com

么,我看了下外网的那个网址确实是404,目测是你戳到外网去了,host没兜住

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template