首页 > PHP:file_get_contents failed to open stream: HTTP request failed

PHP:file_get_contents failed to open stream: HTTP request failed

新建一个test.php

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

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

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

<VirtualHost *:80>
    DocumentRoot "d:/wamp/www/"
    ServerName test1.xiaoci.com 
</VirtualHost>

hosts

127.0.0.1       test1.com
127.0.0.1               test1.xiaoci.com

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

【热门文章】
【热门文章】