这个网址
' http://profile.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=39726387 '
在浏览器中运行良好但cURL返回错误3(格式错误的URL).
关于解决方案的任何想法?
编辑:
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;
}
Run Code Online (Sandbox Code Playgroud)
Mat*_*ick 10
我在运行时得到页面的输出
curl http://profile.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=39726387
Run Code Online (Sandbox Code Playgroud)
这对我也有用:
$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;
Run Code Online (Sandbox Code Playgroud)
编辑:刚刚尝试发布您的代码,它对我来说很好.也许你传入的字符串get_web_page()是错的?