在 AngularJS 中设置应用程序范围的 HTTP 标头 [英] Setting application wide HTTP headers in AngularJS
本文介绍了在 AngularJS 中设置应用程序范围的 HTTP 标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在 angular.module('myApp', []).config()
之外设置 $httpProvider
标头?
Is there a way to set the $httpProvider
headers outside of angular.module('myApp', []).config()
?
登录用户后,我从服务器获取了一个 Auth-Token,我需要将它作为 HTTP 标头添加到所有后续请求中.
I'm getting an Auth-Token from the server after I login the user, and I need to add it as a HTTP Header to all following requests.
推荐答案
$http.defaults.headers.common['Auth-Token'] = 'token';
似乎 headers()
规范了键名.
这篇关于在 AngularJS 中设置应用程序范围的 HTTP 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文