Laravel:GuzzleHttp错误guzzlehttp \\ guzzle \\ src \\ Handler \\ CurlFactory.php

时间:2018-08-15 13:29:11

标签: php laravel laravel-passport

我在我的项目中使用laravel通行证进行API身份验证,我注册了一个用户,并通过GuzzleHttp\ClientAccessTokenController@issueToken发送了发布请求以获取访问令牌,但是当我在{{1 }}无效。

错误:

Postman

我的代码:

 "message": "cURL error 28: Operation timed out after 4009 milliseconds with 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)",
    "exception": "GuzzleHttp\\Exception\\ConnectException",
    "file": "C:\\Users\\BR\\PhpstormProjects\\Arayshgary\\vendor\\guzzlehttp\\guzzle\\src\\Handler\\CurlFactory.php",
    "line": 185,
    "trace": [
        {
            "file": "C:\\Users\\BR\\PhpstormProjects\\Arayshgary\\vendor\\guzzlehttp\\guzzle\\src\\Handler\\CurlFactory.php",
            "line": 149,
            "function": "createRejection",
            "class": "GuzzleHttp\\Handler\\CurlFactory",
            "type": "::"
        },

注册方法:

Route::post('/register','API\User\AuthController@register');

我用 public function register(Request $request) { $request->validate([ 'name'=> 'required|string', 'last_name'=> 'required|string', 'email'=> 'required|string', 'password'=> 'required|string', 'status'=> 'string', 'verified'=> 'string', 'register_type'=> 'string', ]); $user = new User; $user->name = $request->name; $user->last_name = $request->last_name ; $user->email = $request->email; $user->password= bcrypt($request->password); $user->save(); $client = new Client([ 'timeout' => 5.0, ]); $response = $client->request('POST', 'http://127.0.0.1:8000/oauth/token', [ 'form_params' => [ 'grant_type' => 'password', 'client_id' => '4', 'client_secret' => 'LPdfy5ZnhIvlA1QUu1e1Wh33zePnS65hm4b600aJ', 'username' => $request->email, 'password' => $request->password, 'scope' => '', 'provider'=>'barbers' ], ]); return json_decode((string) $response->getBody(), true); } 尝试过,但是没有用。

Curl

路线列表:

$response = Curl::to('http://127.0.0.1:8000/oauth/token')
            ->withData( [
                'grant_type' => 'password',
                'client_id' => '4',
                'client_secret' => 'LPdfy5ZnhIvlA1QUu1e1Wh33zePnS65hm4b600aJ',
                'username' => $request->email,
                'password' => $request->password,
                'scope' => '',
                'provider'=>'barbers',
                ])
            ->enableDebug('C:\Users\BR\Desktop\logFile.txt')
            ->withContentType('application/json')
            ->post();
        return ['data'=>json_decode((string) $response, true)];

并且我使用Passport Multiple-Auth https://github.com/laravel/passport/issues/161#issuecomment-299690583

0 个答案:

没有答案