问题
Basically the title has described everything. I send an api call, get a response, with Authorization in the header, and I want to retrieve this authorization token from the header because it is needed for subsuquent api calls. How should I get this info?
回答1:
You should take a look here: https://docs.angularjs.org/api/ng/service/$http
$http.get('yourUrl').
success(function(data, status, headers, config) {
console.log(headers);
})
回答2:
$http passes headers to the success/error callbacks. The headers parameter is a function that takes a single argument that is an array. It returns all those header values as an array result.
$http.get('/someUrl')
.success(function(data, status, headers) {
console.log(headers(['Authorization']));
});
来源:https://stackoverflow.com/questions/30218801/how-to-retrieve-the-authorization-token-from-the-response-header-of-an-ajax-call