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

1

5

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

Telford answered 27/12, 2018 at 8:50 Comment(2)
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.Grettagreuze
I can't also ping it. This app is actually using github.com/hyn/multi-tenant. for the multisite integrationTelford
M
10

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.

Mandell answered 27/12, 2018 at 10:32 Comment(5)
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"?Telford
@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).Mandell
WAMPServer adds the following to the hosts file 127.0.0.1 test.example.localhost ::1 test.example.localhostUnrealizable
@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).Mandell
@MartinZeitler yep that would definitely affect it! I need to open the hosts file as admin in order to edit and save.Unrealizable

© 2022 - 2024 — McMap. All rights reserved.