此网址
'http://profile.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=39726387'
在浏览器中运行良好,但是cURL返回错误3(格式错误的网址)。
关于解决方法的任何想法?
编辑:
cURL代码:
function get_web_page( $url )
{
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
if (!$errmsg =='') {die($err.':'.$errmsg);}
return $content;
}
答案 0 :(得分:10)
运行时我得到了页面的输出
curl http://profile.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=39726387
这对我也有用:
$ch = curl_init('http://profile.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=39726387');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$out = curl_exec($ch);
curl_close($ch);
echo $out;
编辑:刚试过发布的代码,它对我来说很好用。您传入get_web_page()
的字符串可能错了吗?