N
N
Nikita Musikhin2015-11-04 16:30:01
Angular
Nikita Musikhin, 2015-11-04 16:30:01

How to get data from AngularJS header?

Hello, such a situation, I turn to the server with data for authorization, through the resource, a token comes in the header, but I just don’t understand how to get it out, I’m not banned in Google, a couple of hours of searching did not bear fruit in general:

$http.post(urlForResource+'authorization/user', user).then(function(response){
            console.log(response);
        });

here is the result of what comes in the response header
IEJxm-zoj9zEon1zjBN-UL_7dZEIBb1LDpN0wBqi
and here is what I need to pull out
57uG8EXczn7JUZ_eH44Kqil-A6RDheumh0Wu_wTZ
I will be grateful for the help, or at least for a tip in which direction to dig :)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
amatory10, 2015-11-04
@jestoky

the data that you receive must operate on your own, i.e. where did you define the location of the token?
for example, I put the token in localStorage and can easily get it from there.

A
Alexander Evgenievich, 2015-11-04
@banderos120

The response object has these properties :
data - {string|Object} - The response body transformed with the transform functions.
status - {number} - HTTP status code of the response.
config - {Object} - The configuration object that was used to generate the request.
statusText - {string} - HTTP status text of the response.

Try
response.headers('token'); 
//или
response.headers()['token'];

Y
Yaroslav Lyzlov, 2015-11-04
@dixoNich

It will return a specific
one. It will return the headers object and you will be able to see what you have received and already apply by property.
Here is an example from the documentation
plnkr.co/edit/KnhuUIb0IpqEoNPOXabz?p=preview

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question