ClientException 401未经授权

时间:2016-12-10 10:07:34

标签: laravel-5.3 guzzle6 laravel-passport

我不知道为什么我的代码不起作用,我正在尝试连接两个api
在api 1:

    $token = "my-token";
    $client = new Client();
    $res = $client->request('GET', 'http:.../testHeaders', [
        'headers'        => ['Accept' => 'application/json', 'Authorization' => $token],
    ]);

    $resBody = \GuzzleHttp\json_decode($res->getBody());
    return response()->json($resBody,$res->getStatusCode());

在api 2中:

Route::get('testHeaders',function(\Illuminate\Http\Request $request){
    return response()->json([
        'Accept' => $request->header('Accept'),
        'Authorization' => $request->header('Authorization')
        ],200);
})->middleware('auth:api');

PS:当我用邮递员发送标题(授权和接受)时,它有效, 而且,当我删除中间件时,它就会破坏!!!

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我发布了一个带有wamp的api,另一个带有php artisan服务,它可以工作