cURL错误28:操作在10000毫秒后超时

问题描述 投票:0回答:1

我在使用 Guzzle HTTP 客户端时遇到问题, 当我手动发送

post
请求(使用邮递员)到
oauth/token
时,我正确地获取了令牌并刷新令牌,但是当我使用guzzle发送请求时,它冻结并且暂时没有得到任何响应,超时后返回异常底部

    "message": "cURL error 28: Operation timed out after 10000 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)",
    "exception": "GuzzleHttp\\Exception\\ConnectException",
    "file": "C:\\Users\\SMART\\Desktop\\shopkit-backend\\vendor\\guzzlehttp\\guzzle\\src\\Handler\\CurlFactory.php",
    "line": 200,
    "trace": [
        {
            "file": "C:\\Users\\SMART\\Desktop\\shopkit-backend\\vendor\\guzzlehttp\\guzzle\\src\\Handler\\CurlFactory.php",
            "line": 155,
            "function": "createRejection",
            "class": "GuzzleHttp\\Handler\\CurlFactory",
            "type": "::"
        },
        {
            "file": "C:\\Users\\SMART\\Desktop\\shopkit-backend\\vendor\\guzzlehttp\\guzzle\\src\\Handler\\CurlFactory.php",
            "line": 105,
            "function": "finishError",
            "class": "GuzzleHttp\\Handler\\CurlFactory",
            "type": "::"
        },
        {
            "file": "C:\\Users\\SMART\\Desktop\\shopkit-backend\\vendor\\guzzlehttp\\guzzle\\src\\Handler\\CurlHandler.php",
            "line": 43,
            "function": "finish",
            "class": "GuzzleHttp\\Handler\\CurlFactory",
            "type": "::"
....

这是我的代码

        $client = new \GuzzleHttp\Client([
            'timeout' => 10
        ]); //GuzzleHttp\Client
        try {
            $result = $client->post(url('oauth/token'), [
                'form_params' => [
                    'grant_type' => 'password',
                    'client_id' => $this->_client_id,
                    'client_secret' => $this->_client_secret,
                    'username' => $user->username,
                    'password' => $req->password,
//                'scope' => $scopes
                ]
            ]);
        } catch (\Guzzle\Http\Exception\ConnectException $e) {
            $response = json_encode((string)$e->getResponse()->getBody());
        }

我该怎么办?

laravel guzzle
1个回答
0
投票

检查您的防火墙是否处于活动状态并禁用它

sudo ufw disable
sudo ufw disable
© www.soinside.com 2019 - 2024. All rights reserved.