file_get_contents,HTTP请求失败 [英] file_get_contents, HTTP request failed

查看:102
本文介绍了file_get_contents,HTTP请求失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用file_get_contents从另一个站点获取内容,但是我总是收到无法打开流:HTTP请求失败!" allow_url_fopen已打开,并且我已关闭防火墙进行了测试.但是它仍然发生,还有其他原因吗?

I try to get content from another site by using file_get_contents but I always get "failed to open stream: HTTP request failed!" allow_url_fopen is on, and I have tested with my firewall off. But it still happens, what other reasons can it be?

这是完整的消息 警告:file_get_contents( http://yemto.deviantart.com/):打开流失败:HTTP请求失败!在第15行的D:\ xampp \ htdocs \ deviantart \ webcam \ img.php中

Here is the full message Warning: file_get_contents(http://yemto.deviantart.com/): failed to open stream: HTTP request failed! in D:\xampp\htdocs\deviantart\webcam\img.php on line 15

和代码

//Load the page into a DOMDocument
$file = file_get_contents(strToLower("http://".$user.".deviantart.com/"));//TO-DO <-- if deivantart name is empty, it crashes
$doc = new DOMDocument();
@$doc -> loadHTML($file);

推荐答案

如果客户端未发送User-Agent标头,则您的网络服务器会立即关闭连接.尝试在php.ini中添加user_agent选项,或输入:

Your webserver closes the connection immediately if the client doesn't send a User-Agent header. Try adding a user_agent option to your php.ini, or put:

ini_set('user_agent', 'PHP');

在您的脚本中.

这篇关于file_get_contents,HTTP请求失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆