本文介绍了不发送的X要求,随着AngularJS $资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的角度1.1.5和我使用的是$资源做一个XHR到REST服务,但它好像在$资源没有附加头为X-要求,随着作为XMLHtt prequest,是一个正常的行为??我需要手动添加页眉?

 函数loginCtrl($范围,$资源){
    $ scope.submit =功能(){
         VAR资源= $资源('/原料药/用户/登录',{},
              {
                  验证:{
                      方法:POST,
                      IsArray的:假的,
                      标题:{
                          __RequestVerificationToken':$ scope.loginRequest.Token                      }
                  }
              });
         resource.authenticate($ scope.loginRequest);
    };
}


解决方案

只需添加到您的应用

  myAppModule.config(['$ httpProvider',函数($ httpProvider){
    $ httpProvider.defaults.headers.common ['X-要求-随着'] ='XMLHtt prequest';
}]);

I'm using angular 1.1.5 and I'm using a $resource to make a XHR to a REST service but it seems like the the $resource isn't appending the header as X-Requested-With as XMLHttpRequest, is that a normal behavior? and Do I need to append the header manually?

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);
    };
}
解决方案

Just add this to your app

myAppModule.config(['$httpProvider', function($httpProvider) {
    $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
}]);

这篇关于不发送的X要求,随着AngularJS $资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 16:44