failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

虽然fopen和file_get_contents都可以直接给url参数获取内容,有时会出现以下错误:

failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found  

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

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; 
} 

 

posted on 2018-03-15 10:30  FantasyBoy  阅读(1018)  评论(0编辑  收藏  举报