[英]cURL 'malformed url'
這個網址
' 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;
}
我在運行時得到頁面的輸出
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()
的字符串是錯誤的?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.