虽然php手册上说fopen和file_get_contents都可以直接给url参数获取内容,但总是会报如下这个错误

Warning: fopen(http://leoncom.org/) [function.readfile]: failed to open stream: HTTP request failed!

采用curl获取url数据就可以避免这种时不时的错误了

[code language="php"]
function geturldata($url)
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
$content = curl_exec($ch);
return $content;
}
[/code]

转载请注明来源:Leoncom-《php解决failed to open stream: HTTP request failed!》
, ,
Trackback

no comment untill now

Add your comment now