I'm using laradock and I can access the page in browser http://localhost:8088/api/getakicks/get without any problems.

But when I try to access it in controller I'm getting this error:

GuzzleHttp \ Exception \ ConnectException cURL error 7: Failed to connect to localhost port 8088: Connection refused

The code I use:

  $client = new \GuzzleHttp\Client();

  // Set various headers on a request
  $client->request('GET', 'http://localhost:8088/api/getakicks/get');
2

There are 2 best solutions below

3
On

changed the IP address from localhost:8088 to windows IP address 192.168.x.x:8088.

1
On

Get IP address on MAC, click on wifi icon -> Open Network Preferences -> then copy the IP address 192.168.100.41 (own unique IP) and replace with xxx in below code

$client->request('GET', 'http://xxx.xxx.xx.x:8088/api/getakicks/get');