ホームページ  >  記事  >  バックエンド開発  >  PHP:file_get_contents failed to open stream: HTTP request failed

PHP:file_get_contents failed to open stream: HTTP request failed

WBOY
WBOYオリジナル
2016-06-06 20:46:152142ブラウズ

新建一个test.php

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

然后访问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>

hosts

<code>127.0.0.1       test1.com
127.0.0.1               test1.xiaoci.com
</code>

并且设置了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>

然后访问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>

hosts

<code>127.0.0.1       test1.com
127.0.0.1               test1.xiaoci.com
</code>

并且设置了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没兜住

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。