Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cURL 'malformed url'

Tags:

url

php

curl

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
        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;
}
like image 570
Mark Avatar asked Jan 24 '10 07:01

Mark


People also ask

Why is this URL malformed?

This violation indicates that a request that was not created by a browser, and does not comply with HTTP standards, has been sent to the server. This may be the result of of an HTTP request being manually crafted or of a client tunneling other protocols over HTTP.

What is URL malformed?

Nov 9, 2021. If the Base URL malformed or empty error occurs, it means that you indicated an invalid or empty URL marked by the HTML tag, which defines the path of relative links on the site.

How do I fix curl error 3?

The error curl: (3) URL using bad/illegal format or missing URL could be caused by a character issue with the passwords. Characters such as @ or & or other symbols may be problematic on the command line. To fix this issue, add double quotes around your URL.


1 Answers

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?

like image 191
Matt McCormick Avatar answered Sep 22 '22 17:09

Matt McCormick