php - curl 'malformed url'

标签 php url curl

这个网址

'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;
}

最佳答案

运行时得到页面的输出

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() 的字符串是错误的?

关于php - curl 'malformed url',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2126300/

相关文章:

php - 带数字的函数名

php - 我怎样才能用jquery加载图片?

node.js - 从查询字符串中提取 URL

java - 如何使用java中的正则表达式从移动浏览器中的YouTube url获取视频ID

sql - bash 脚本 curl 命令中的单引号不断转换为双引号

PHP类在构造函数中分配属性

php - 同时多个php请求,第二个请求直到第一次完成才开始

javascript - 浏览器从 url 中剥离编码的点字符

curl - 我正在尝试使用Curl向URL发出POST请求,但收到此错误?

curl - 如何使用 cURL -XGET -d' {"query": "aaa"}' 之类的正文触发 Postman GET 请求