开发者社区> 问答> 正文

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,结果报错如下:
screenshot
screenshot
注意: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错误

展开
收起
落地花开啦 2016-06-17 17:44:28 3368 0
1 条回答
写回答
取消 提交回答
  • 喜欢技术,喜欢努力的人

    ost难道不应该是

    127.0.0.1 test1.xiaoci.com

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

    2019-07-17 19:43:19
    赞同 展开评论 打赏
问答分类:
PHP
问答地址:
问答排行榜
最热
最新

相关电子书

更多
阿里云栖开发者沙龙PHP技术专场-深入浅出网络编程与swoole内核-吴镇宇 立即下载
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载