AngularJS Adding a header to the $http.get

前端 未结 2 1691
有刺的猬
有刺的猬 2021-01-21 11:57

I\'m trying to add the \'Authorization\' header containing a token for future HTTP request. Retrieval of the token seems to be fine however when making a get request it fails wi

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-21 12:29

    Try adding this in your config block and set the token in your rootscope

    $httpProvider.interceptors.push({
        request: function (config) {
            config.headers.Authorization = $rootScope.token;
            return config;
        }
    })
    

提交回复
热议问题