开发者

cURL 'malformed url'

开发者 https://www.devze.com 2022-12-17 03:59 出处:网络
This url \'http://profile.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=39726387\' works perfectly well in a browser but cURL return\'s error 3 (malformed url).

This url

'http://profile.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=39726387'

works perfectly well in a browser but cURL return's error 3 (malformed url).

Any ideas on a work around?

EDIT:

cURL code:

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
        CURLOP开发者_如何学运维T_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;
}


I get the output of the page when running

curl http://profile.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=39726387

This also works for me:

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

Edit: Just tried your code posted and it works fine for me. Perhaps the string you are passing into get_web_page() is wrong?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号