Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aschorr's avatar

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

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...

0 likes
1 reply
jove's avatar

Are there actually running anything that you can connect to at HTTPS on foo.app? What you are getting is that there cannot be made an connection so I would assume foo.app:443 doesn't exist. Also it's mixed with mixapp.app and foo.app, have you changed anything? But it's the same for that, no service on port 443 (HTTPS).

Maybe port 80 (HTTP)?

Please or to participate in this conversation.