我在点击"http://Google.com“时收到以下错误"Warning: file_get_contents无法打开流: HTTP请求失败!HTTP/1.0400错误的请求”
<?php
$content = file_get_contents("http://www.google.com");
if (strpos($http_response_header[0], "200")) {
echo "SUCCESS";
}
else {
echo "FAILED";
}
?>由于这个问题,我无法使用WAMP( .I version2.2.22,PHPversion5.4.3)解析网址PHP。
采取的步骤:-在php.ini中启用1.allow_url_fopen 2.尝试编码URL3.甚至使用Curl php函数得到同样的问题。4.允许的防火墙打开
请帮帮忙。
发布于 2012-07-28 19:24:15
$html = @file_get_html($url);
if($html==FALSE) {
echo 'error';
} else {
echo 'success';
}检查一下,这里的$url是www.google.com.then,您会得到正确的结果
发布于 2012-07-28 19:22:03
请求实际成功后,您就拥有了$content格式的页面。但是你对成功做了一个错误的测试。url返回的不是200,而是302。
发布于 2012-07-28 19:24:11
这是因为它返回状态302 (已找到)
echo $http_response_header[0]; //返回‘找到HTTP/1.0 302’
https://stackoverflow.com/questions/11700516
复制相似问题