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

Yves Gonzaga picture Yves Gonzaga · Dec 27, 2018 · Viewed 18.8k times · Source

I am trying to curl to my localhost laravel site. I am using XAMPP 7.1 When I try to reconnect this code always gives an error (instead of 200 OK response)

Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: cURL error 6: Could not resolve host: test.example.localhost (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in D:\xamp7.1\htdocs\wittymanager\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:185 Stack trace: #0 D:\xamp7.1\htdocs\wittymanager\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(149): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array) #1 D:\xamp7.1\htdocs\wittymanager\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(102): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #2 D:\xamp7.1\htdocs\wittymanager\vendor\guzzlehttp\guzzle\src\Handler\CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #3 D:\xamp7.1\htdocs\wittymanager\vendor\guzzlehttp\guzzle in D:\xamp7.1\htdocs\wittymanager\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 185

 // URL = http://test.example.localhost/api/lang-sync
 public static function test($url, $data) {   
    $client = new \GuzzleHttp\Client();

    $res = $client->request('POST', $url, $data);

    $response = $res->getBody();

    if($res->getStatusCode() == 200) 
    {
        print_r($res);

    } else {

        print_r($response);

    }
 }

On staging server it is ok. Restarting xampp doesn't help.

EDIT:

test.example.localhost is already added on the host file.

This a wordpress plugin sending http request to a Laravel API.

This app is actually using https://github.com/hyn/multi-tenant. for the multisite integration

Answer

Martin Zeitler picture Martin Zeitler · Dec 27, 2018

it reads:

Could not resolve host: test.example.localhost

open C:\Windows\System32\Drivers\etc\hosts and add this entry:

127.0.0.1 test.example.localhost

so that the host-name will be known.