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

26,747

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.

Share:
26,747
Yves Gonzaga
Author by

Yves Gonzaga

Updated on January 03, 2020

Comments

  • Yves Gonzaga
    Yves Gonzaga over 4 years

    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

    • Ulrich Eckhardt
      Ulrich Eckhardt over 5 years
      Can you ping it? If ping also says it can't resolve the name, that pretty much proves that your problem has nothing to do with php, curl and guzzlehttp but rather your DNS setup.
    • Yves Gonzaga
      Yves Gonzaga over 5 years
      I can't also ping it. This app is actually using github.com/hyn/multi-tenant. for the multisite integration
  • Yves Gonzaga
    Yves Gonzaga over 5 years
    I read somewhere I can't remember where but I remember it stated that "sometimes it is because of the DNS issue on my local machine"?
  • Martin Zeitler
    Martin Zeitler over 5 years
    @YvesGonzaga can you access it in a web-browser? or how about adding a fully qualified local-loopback hostname, alike:test.example.localhost.localdomain? also setting the IP address of the other interface instead of 127.0.0.1 might help, so that it won't use the loop-back interface (in case the local web-server does not listen to all available IP).
  • Andrew Schultz
    Andrew Schultz about 3 years
    WAMPServer adds the following to the hosts file 127.0.0.1 test.example.localhost ::1 test.example.localhost
  • Martin Zeitler
    Martin Zeitler about 3 years
    @AndrewSchultz Having installed without admin rights may have prevented that edit... the file still appears to be editable in Windows 10 (despite it's being abused for phising attempts).
  • Andrew Schultz
    Andrew Schultz about 3 years
    @MartinZeitler yep that would definitely affect it! I need to open the hosts file as admin in order to edit and save.
  • Raging Vids
    Raging Vids over 2 years
    @MartinZeitler Thank you so much. :D