【发布时间】:2015-08-05 20:13:52
【问题描述】:
我从 hipster generator 生成一个应用程序并创建一个新工厂来调用我的服务。
所有现有服务都在标头中使用 x-csrf 令牌调用,但是当我尝试使用我的工厂进行 Get 或 Post 时,我得到错误 401, Unauthorized
在我的应用配置中,我有这个:
//enable CSRF
$httpProvider.defaults.xsrfCookieName = 'CSRF-TOKEN';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRF-TOKEN';
这是我的工厂:
angular.module('jhipsterApp')
.factory('WalletsService', function ($http) {
return {
findAll: function () {
return $http.get('api/walletslist/').then(function (response) {
return response.data;
});
}
};
});
当我执行 findAll 函数时,我得到这个错误:
[Error] Failed to load resource: the server responded with a status of 401 (Unauthorized) (walletslist, line 0)
x-csrf 保存在 cookie 中,但我如何在标头中传递它?
谢谢
【问题讨论】: