Reputation: 2833
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');
Upvotes: 5
Views: 21692
Reputation: 16
When using Docker, localhost
in the container points to the container itself, not your host machine. In your case changing http://localhost:8088
to http://host.docker.internal:8088
lets the container access services on your host’s localhost
, which fixes the connection issue.
Upvotes: 0
Reputation: 103
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');
Upvotes: 9
Reputation: 161
changed the IP address from localhost:8088 to windows IP address 192.168.x.x:8088.
Upvotes: 1