aschorr
1 month ago

Guzzle / cURL Connection refused - Failed to connect to port 443

Posted 1 month ago by aschorr

I'm using Guzzle to make a an authorization request to login and seem to be getting connection refused.

My code in my custom controller is

    public function login(Request $request)
    {
        $http = new \GuzzleHttp\Client();
        try {
            $response = $http->post('https://foo.app/oauth/token/', [
                'form_params' => [
                    'grant_type' => 'password',
                    'client_id' => config('services.passport.client_id'),
                    'client_secret' => config('services.passport.client_secret'),
                    'username' => $request->username,
                    'password' => $request->password,
                ]
            ]);
            return $response->getBody();
        } catch (\GuzzleHttp\Exception\BadResponseException $e) {
            if ($e->getCode() === 400) {
                return response()->json('Invalid Request. Please enter a username or a password.', $e->getCode());
            } else if ($e->getCode() === 401) {
                return response()->json('Your credentials are incorrect. Please try again', $e->getCode());
            }
            return response()->json('Something went wrong on the server.', $e->getCode());
        }
    }

and the response I get back is:

[2019-09-17 13:41:57] local.ERROR: cURL error 7: Failed to connect to mixapp.app port 443: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) {"exception":"[object] (GuzzleHttp\Exception\ConnectException(code: 0): cURL error 7: Failed to connect to foo.app port 443: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) at /Users/andrewschorr/Workspaces/laravel_projects/MixApp/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:185)

Has anyone ran into this before? Valet is great, but it abstracts much of this stuff away and makes debugging a bit more of a pain...

Please sign in or create an account to participate in this conversation.