相关文章推荐
留胡子的电影票  ·  Install and Set Up ...·  1 月前    · 
刚失恋的水煮肉  ·  curl ...·  1 周前    · 
高大的包子  ·  python爬虫: ...·  1 年前    · 
大力的荒野  ·  Filezilla for mac ...·  1 年前    · 
气势凌人的拐杖  ·  How to work with ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I want to try out the guzzle library and am following through their quickstart tutorial to make http requests to an api.

Yet it doesn't seem to work, because I get the following error:

cURL error 3: <url> malformed

Since I have never worked with cURL before, I don't even know how to respond to that error message. Here is my code with the request I am making:

    $client = new Client();
    $client->get('/', ['verify' => true]);
    $response = $client->get('https://api.github.com/');
    dd($response);

I am using the Laravel 5 framework and calling the index method in my HomeController. Also am using WAMP.

I would appreciate any help and suggestion, because I would like to try Guzzle out.

Here is a picture of the Error Message I get:

@loveAndHappiness did you get any solution to solve this issue ? i have same same issue in my code :( please help me – Irtiza shahid Jul 27, 2015 at 6:54 I hadn't had the time to implement any solution to this project yet, so I don't know if the provided solution solved the issue. – LoveAndHappiness Jul 28, 2015 at 13:28

In case you came here because you googled "Guzzle returns cURL error 3: malformed" check the client parameter. In some version it's base_uri and other base_url

    $client = new Client([
        'base_uri' => 'http://localhost:8000',  // <-- base_uri instead of base_url
                Same thing here, I had the URL with / in the end. Left it without / then added the / in the beginning of my call and it worked.
– Mihail Minkov
                Sep 17, 2021 at 23:44

If you want to disable verification (don't do this!):

$response = $client->get('https://api.github.com/', ['verify' => false]);

Rather than disabling verification entirely, this can likely be fixed by providing proper CA bundle file. See verify in Guzzle documentation.

$client->setDefaultOption(
    'verify', 
    'C:\Program Files (x86)\Git\bin\curl-ca-bundle.crt'
                Actually that is not the issue, because without this line, I get another error "cURL error 60: SSL certificate problem: unable to get local issuer certificate", and the guzzle faq says that this line needs to be there.
– LoveAndHappiness
                Apr 19, 2015 at 5:39
$client->get('/', ['verify' => true]);

That is what is throwing the error. The third line is okay.

The error is means what it says. The URL / is obviously not valid. When you instantiate the client, use the base_uri option, or specify a full URL in the call to get().

In line one when initializing the guzzle client he had not passed in a url. So in line two, when he uses '/', there is no base url and an error is bound to be thrown [malformed url] – Teliov Apr 26, 2016 at 14:36

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.