【发布时间】:2017-06-14 09:09:00
【问题描述】:
我正在尝试在每个请求的标头中发送一个令牌。首先,我尝试做更复杂的事情,比如保存在本地存储中,但是现在,我尝试添加一个带有随机标记字符串的该死的标头,但它仍然没有添加标头。为什么?这是app.js,我这里只放这个:
'use strict';
function testInterceptor() {
return {
request: function(config) {
config.headers['x-token'] = 'lalalalala';
console.log(config);
console.log("Aaa");
return config;
}
}
}
var app = angular.module('myapp', ['oc.lazyLoad', 'LocalStorageModule', 'oc.lazyLoad', 'ngRoute', 'naif.base64', 'ui.router', 'ngAnimate', 'ui.bootstrap']);
app.factory('testInterceptor', testInterceptor);
app.config(function($httpProvider) {
$httpProvider.interceptors.push('testInterceptor');
});
在 console.log 中它甚至没有打印任何东西。我还评论了身份验证提供程序并让:
Default:
Anonymous: ~
在 security.yml 中
当我尝试使用邮递员或在浏览器中调用我的应用程序时,它不会添加标题。为什么我做错了?
【问题讨论】:
标签: angular http interceptor