Alladin
Alladin

Reputation: 1052

cURL error 7: Failed to connect to localhost port 4444: Connection refused

I have been trying to send a request post to my localhost using guzzlehttp/guzzle v6.2.3 but i keep getting the error shown in the title. I have tried to make the call using Postman and it works fine. I have been doing some searching and found that most people solve the issue by changing localhost to 127.0.0.1 or to the IPv4.. I have tried all of them but still getting the same error every time. Here is my code:

$client = new Client();
$res = $client>post('http://localhost:4444/api/abc/xyz',request(['x', 'y']));
echo $res->getStatusCode();

Please assist me resolving the problem.

Upvotes: 1

Views: 5121

Answers (1)

Alladin
Alladin

Reputation: 1052

I have found the solution. actually the issue is caused because i'm using homestead, so I can't use localhost as it will browse the VM localhost. I had to change the path to

http://10.0.2.2/api/abc/xyz

Upvotes: 2

Related Questions