PHP:file_get_contents failed to open stream: HTTP request failed
迷茫
迷茫 2017-04-10 14:44:29
[PHP讨论组]

新建一个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错误

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回复(1)
阿神

host难道不应该是

127.0.0.1 test1.xiaoci.com

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号