我正在使用angular 1.6.4。我試圖在每個請求上發送一個Auth頭文件,但客戶端似乎沒有在請求中發送頭文件。不知道我做錯了什麼......Angular不會在每個請求上發送頭文件
這是我app.js
angular.module("myApp", ['ngRoute', 'ngMaterial', 'toolbar', 'authService'])
.config(function ($httpProvider) {
$httpProvider.interceptors.push('AuthInterceptor');
});
和我AuthInterceptor
angular.module('authService', [])
.factory('AuthInterceptor', function() {
return function(config) {
request: {
config.headers.Authentication = 'thisIsATestToken';
return config;
}
};
});
然而,在服務端我從來沒有得到過「認證'標題。
我看過我的例子,這正是他們如何做到的。我只是在localhost上本地運行應用程序。
你確定發送'Authentication'頭,或者是' Authorization'? – 31piy
看看你的工廠,你正在返回函數,而不是對象字面值,也使用'request:function(config){....' – Kanagu