How to retrieve the authorization token from the response header of an ajax call in angularjs?

丶灬走出姿态 提交于 2019-12-11 03:51:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!