4

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

Yves Gonzaga
  • 105
  • 1
  • 2
  • 12
  • 1
    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. – Ulrich Eckhardt Dec 27 '18 at 14:06
  • I can't also ping it. This app is actually using https://github.com/hyn/multi-tenant. for the multisite integration – Yves Gonzaga Jan 03 '19 at 02:50

1 Answers1

8

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.

Martin Zeitler
  • 49,224
  • 12
  • 97
  • 156
  • 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"? – Yves Gonzaga Dec 27 '18 at 13:54
  • @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). – Martin Zeitler Jan 03 '19 at 12:15
  • WAMPServer adds the following to the hosts file 127.0.0.1 test.example.localhost ::1 test.example.localhost – Andrew Schultz Mar 04 '21 at 07:27
  • @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). – Martin Zeitler Mar 04 '21 at 07:35
  • @MartinZeitler yep that would definitely affect it! I need to open the hosts file as admin in order to edit and save. – Andrew Schultz Mar 04 '21 at 07:36