I’m trying to perform a search of all registered products based on user_id.
In the postman, I get this list, after performing the authentication.
In the image below, you can see the return 200 in the request.
In my code I get 401. Can you help me analyze what I might be doing wrong?
public function index()
{
$session = $this->getRequest()->getSession();
$http = new Client(['headers' => ['x-access-token' => 'Bearer '. $session->read('Config.TOKEN'),]]);
$response = $http->get('http://localhost:8889/api/produto/buscaProdutosPorIdUsuario/1');
debug($response);
if ($response->getStatusCode() == 401) {
return $this->redirect($this->referer());
}
if ($response->isOk()) {
$json = $response->getJSON();
$this->set('json', $json["data"]);
$this->set(compact('json'));
}
}