我正在使用angular 1.1.5,并且正在使用$ resource将XHR制作为REST服务,但似乎$ resource并未将标头附加为X- Requested-With和XMLHttpRequest, 是正常行为? 和我是否需要手动附加标题?
function loginCtrl($scope,$resource) { $scope.submit = function () { var resource = $resource('/Api/User/login', {}, { authenticate: { method: 'POST', isArray: false, headers: { '__RequestVerificationToken': $scope.loginRequest.Token } } }); resource.authenticate($scope.loginRequest); }; }
只需将其添加到您的应用中
myAppModule.config(['$httpProvider', function($httpProvider) { $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; }]);