Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel passport: Error cURL error 7: Failed to connect to localhost port 8080 after 0 ms

  • To run directly through Postman, I receive the result.

  • When running through the server localhost:8080, I am encountering an error. I would highly appreciate any assistance you can provide. Thanks

public function getTokenAndRefreshToken(OClient $oClient) {
    $http = new Client;
    

    $response = $http->request('POST', 'http://localhost:8080/oauth/token', [
            'grant_type' => 'password',
            'client_id' => 20,
            'client_secret' => 'R9pywYcu9cRdRBJWv*********rJBwdSOSq',
            'username' => '[email protected]',
            'password' => "123456",
            'scope' => '*',
    ]);
    $result = json_decode((string) $response->getBody(), true);
    return response()->json($result, $this->successStatus);
}

Illuminate\Http\Client\ConnectionException: cURL error 7: Failed to connect to localhost port 8080 after 0 ms: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://localhost:8080/oauth/token in file /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Client/PendingRequest.php on line 856

like image 466
Tony nguyen Avatar asked Dec 21 '25 09:12

Tony nguyen


1 Answers

I don't know where you're running your app, if it's fully locally, on a VM or in container. I get the same error so maybe this can help. In my case I was using a container:

$response = Http::get('host.docker.internal:<APP_PORT>...')
like image 156
Emmanuel Morales Avatar answered Dec 23 '25 22:12

Emmanuel Morales



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!