如何从angularjs中的ajax调用的响应头中检索授权令牌?

时间:2015-05-13 15:07:33

标签: javascript angularjs http-headers

基本上标题描述了一切。我发送一个api调用,得到一个响应,标题中有Authorization,我想从标题中检索这个授权令牌,因为它是次要的api调用所需要的。我应该如何获得这些信息?

2 个答案:

答案 0 :(得分:1)

你应该看看这里:https://docs.angularjs.org/api/ng/service/$http

$http.get('yourUrl').
  success(function(data, status, headers, config) {
    console.log(headers);
  })

答案 1 :(得分:0)

$httpheaders传递给成功/错误回调。 headers参数是一个函数,它接受一个作为数组的参数。它将所有这些标头值作为数组结果返回。

$http.get('/someUrl')
     .success(function(data, status, headers) {
         console.log(headers(['Authorization']));
     });