cURL'网址格式错误' [英] cURL 'malformed url'

查看:143
本文介绍了cURL'网址格式错误'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此网址

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

工作完全可以在浏览器中使用,但是cURL返回错误3(URL格式错误)。

works perfectly well in a browser but cURL return's error 3 (malformed 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()的字符串是错误的?

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

这篇关于cURL'网址格式错误'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆