angular $ resource使用DELETE方法发送请求,请求正文获取415错误

时间:2016-10-19 07:02:09

标签: angularjs resources

我通过angular $ resource发送删除任务,但它总是得到415错误,请求正文变成了字符串看起来像一个get请求。

'use strict';

(function(angular, window){

var authsys = angular.module('authsysApp');

authsys.factory('$_privilege', ['$resource', '$q', '$notify', function($resource, $q, $notify){

    var resource = {
        //删除权限
        batchRemovePrivilege: $resource(window.ctxPath + '/rolepri/batchDeletePrivilegeFromRole', {}, {delete:{method: 'DELETE'}})
    };

    return {
        batchRemovePrivilege: batchRemovePrivilege
    };

    function batchRemovePrivilege(params){

        var q = resource.batchRemovePrivilege.delete(params).$promise;
        return q.then(function(){
            return true;
        });
    }


}]);

})(angular, window);

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试在您的请求中添加标题:

var resource = {
    //删除权限
    batchRemovePrivilege: function(params){
           return $http({
                method: 'DELETE',
                url: window.ctxPath + '/rolepri/batchDeletePrivilegeFromRole',
                data: params,
                headers: {'Content-Type': 'application/x-www-form-urlencoded'}
           });
    }
};

<强>执行:

var q = resource.batchRemovePrivilege(params).$promise;