当我尝试使用curl或file_get_contents从http://example.com/读取像http://example.com/python/json/这样的东西时,我应该得到一个http://example.com/响应,但是我得到了一个404错误。在我自己的域外使用curl或任何其他方法都能很好地工作。
echo file_get_contents('http://example.com/python/json/'); => 404
echo file_get_contents('http://google.com'); => OK同样的脚本也可以在我的笔记本电脑上运行,但是我不知道有什么不同。
发布于 2008-10-30 18:59:34
看起来example.com不是IP地址的默认域,并且file_get_contents使用HTTP1.0而不是HTTP1.1,并且/或者不发送Host:头。在PHP中尝试curl支持:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://example.com/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);或者,/etc/hosts文件为example.com设置了错误的IP地址。
发布于 2008-10-30 19:00:38
可能是与域名有关的事情?当然,您不想在这里展示它,所以您可能需要做一些工作,但我想可以通过web浏览器(如果您只使用命令行,则可以使用命令行工具,如GET )访问该URL。
您也可以直接ping和/或traceroute到域-结果可能很有启发性。
https://stackoverflow.com/questions/251317
复制相似问题