我正在使用带有风帆后端的Angularjs
Sails backend
(csrf.js)
module.exports.csrf = true;
module.exports.csrf = {
grantTokenViaAjax: true,
origin: 'www.frontend.com'
}
(cors.js)
allRoutes: true,
credentials: true,
origin: 'http://www.frontend.com',
methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',
headers: 'X-CSRF-Token,Content-Type'
错误
能够通过ajax请求获取csrfToken
在跨域执行发布请求时显示csrf不匹配错误
http请求
obj.fetchCsrfToken = function(){
promise = $http.get('http://www.backend.com/csrfToken');
return promise;
}
发布请求
$http.post('http://www.backend.com/api/doWork/', {
one: $scope.workForm.dataOne
, two: $scope.workForm.dataTwo
},{withCredentials:true}).then(function(response){
console.log(response);
});
提前谢谢