Angularjs 不在每个请求上发送头

Angularjs 不在每个请求上发送头,angularjs,Angularjs,我用的是angular 1.6.4。我试图在每个请求上发送一个Auth头,但是客户端似乎没有在请求中发送头。不知道我做错了什么 这是我的app.js angular.module("myApp", ['ngRoute', 'ngMaterial', 'toolbar', 'authService']) .config(function ($httpProvider) { $httpProvider.interceptors.push('AuthInterceptor');

我用的是angular 1.6.4。我试图在每个请求上发送一个Auth头,但是客户端似乎没有在请求中发送头。不知道我做错了什么

这是我的app.js

angular.module("myApp", ['ngRoute', 'ngMaterial', 'toolbar', 'authService'])
    .config(function ($httpProvider) {
        $httpProvider.interceptors.push('AuthInterceptor');
    });
还有我的截取器

angular.module('authService', [])
.factory('AuthInterceptor', function() {
    return function(config) {
        request: {
            config.headers.Authentication = 'thisIsATestToken';
            return config;
        }
    };
});
然而,在服务端,我从未获得“身份验证”头


我已经看了我的例子,这正是他们如何做到这一点。我只是在本地主机上本地运行应用程序。

您可以在主模块本身中使用此方法

angular.module('myApp', [])
    .run(['$http', function($http) {
      $http.defaults.headers.common.Authorization = 'thisIsATestToken';
    }])

更改您的身份验证拦截器工厂,如下所示

angular.module('authService', [])
    .factory('AuthInterceptor', function() {
        return {
            request: function(config) {
                config.headers.Authentication = 'thisIsATestToken';
                return config;
            }
        };
    });

你确定要发送
身份验证
标题,还是
授权
?看看你的工厂,你返回的是函数而不是对象文字,还使用
请求:函数(配置){..
真的很奇怪,同样的问题。最令人惊讶的是,我没有碰我的代码,它已经坏了。寻求更改,一切都是稳定的。问题在哪里?我也试过了。当我看到请求时,头没有发送。