Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel guzzle cURL error 6: Could not resolve host: http (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

Tags:

php

curl

laravel

On my development my code is working properly. When I push to my server it become error.

cURL error 6: Could not resolve host: http (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

Here is my code:

use GuzzleHttp\Client;

try {
    $client = new Client();
    $client->request('POST', env('API_DOMAIN') . '/v1/user/auth/verified_email',
        ['headers' => ['Authorization' => 'cm9vcGlhLnVzZXIud2ViOkY0RVN3VXJheS1qVVB1a18='],
         'query'   => ['token' => $key]]);

    return redirect('/')->with('status', 'Your email has been verified. Thanks!')->with('statusType', 'success');
} catch (ConnectException $e) {
    Log::error($e);
    return redirect('/');
}

Any solution?

Thanks

like image 988
ssuhat Avatar asked Aug 12 '16 02:08

ssuhat


3 Answers

My solution is to clear all type of caches in Artisan.

Run these commands together:

php artisan route:clear
php artisan config:clear
php artisan cache:clear
like image 94
Matianda Avatar answered Nov 14 '22 03:11

Matianda


I spent a day to find that the best practice is to actually catch Exceptions in the following manner:

catch(\Exception $ex)

That \ makes all the difference! so DO NOT use :

catch(Exception $ex)

You can put this catch at the end where all other specific exceptions are caught.

like image 2
Amir Hajiha Avatar answered Nov 14 '22 02:11

Amir Hajiha


Your API_DOMAIN may not have been set to a proper url (did it start with http:// or https://)?

It may also be worth a try to restart the web server (e.g. restart nginx).

It could also be a connectivity issue on your server. You can try a reboot of the VPS or check if the firewall did not block your outgoing request. Maybe disable iptables or firewalld for a moment.

There could also be issues with the DNS for the API_DOMAIN. Maybe you did configure it locally in your /etc/hosts on your developmnet environment but not on production. You may check if the dns resolves properly or add it to your /etc/hosts file on your production server.

like image 1
Roderik Avatar answered Nov 14 '22 03:11

Roderik