【问题标题】:How to retrieve the authorization token from the response header of an ajax call in angularjs?如何从angularjs中ajax调用的响应头中检索授权令牌?
【发布时间】:2015-05-13 15:07:33
【问题描述】:

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

【问题讨论】:

标签: javascript angularjs http-headers


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2014-02-07
      • 2015-11-03
      • 2016-03-08
      • 2017-11-13
      • 2020-07-03
      • 2017-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多