php cURL '格式错误的网址'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2126300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:09:15  来源:igfitidea点击:

cURL 'malformed url'

phpurlcurl

提问by Mark

This url

这个网址

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

' 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).

在浏览器中运行良好,但 cURL 返回错误 3(格式错误的 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
        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;
}

采纳答案by Matt McCormick

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?

编辑:刚刚试过你发布的代码,它对我来说很好用。也许你传入的字符串get_web_page()是错误的?