mardi 22 mai 2018

passport api work in postman not in other application

I create personal access token using laravel. and create post method API for the following URL

Route::middleware('auth:api')->post('/create-project','ProjectController@saveProject')->name('saveProject');

then access this URL from another project using Guzzle client

$client = new Client([
          'base_uri' => 'http://project.test/',
          'headers' => [
                    'Accept' => 'application/json',
                    'authorization' => 'Bearer ' . env('PROJECT_API_TOKEN'),
                    'Content-Type' => 'application/json'
                ]
            ]);
            $body = array('project_name' => 'test');
            $r = $client->request('POST', 'api/create-project',['body' => json_encode($body)]);

it always returns following response

resulted in a `401 Unauthorized` response: {"message":"Unauthenticated."}

but work in postman



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2GIblOu
via IFTTT

Aucun commentaire:

Enregistrer un commentaire