How to access a specific http header?

Asked

Viewed 1,207 times

5

I have a Rest API in Java, which makes use of JWT to authenticate users and generate tokens to access their resources. I have an application in Angularjs, which should consume these resources, but I first need to request a token in the API. I would like to know how to access the token that is in the header of the POST request response. By Angular I’m not getting access to this, however, in the browser I can see the token in the request response.

Exemplo da resposta da requisição, com o token no header

1 answer

3

$http.post('/login', user).then(function(response) {
    var authorization = response.headers('Authorization');
});

With the headers() function you can access any of the header attributes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.