38

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:

Laravel 5 Error Message

3
  • if my answer below was helpful, you can accept it :) Apr 21, 2015 at 15:06
  • @loveAndHappiness did you get any solution to solve this issue ? i have same same issue in my code :( please help me 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. Jul 28, 2015 at 13:28

4 Answers 4

26

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
    ]);
3
  • 1
    This solved my problem. Thank you. I got the base_uri value from APP_URL in .env file. Nov 18, 2019 at 7:40
  • 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. Sep 17, 2021 at 23:44
  • I know very old post, but thanks, you saved my day
    – Fahim
    Jun 29, 2022 at 18:05
13

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'
);
2
  • 1
    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. Apr 19, 2015 at 5:39
  • 1
    Not sure how this solves a "malformed URL" error, or why it was marked accepted.
    – miken32
    Nov 23, 2021 at 16:43
11

You should not have this call:

$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().

2
  • What is the problem with line 2 and why should OP not have it? Apr 11, 2016 at 20:31
  • 1
    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
-1

In my case, I mistakenly named my environment file as "env"

Make sure it exists at root path and named ".env"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.