CHAD.DING CHAD.DING - 9 months ago 72
AngularJS Question

angular $resource send request with DELETE method and request body get 415 error

I send a delete quest via angular $resource, however it always get 415 error and the request body was turn to string looks like a get request.

'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

Tal Tal
Answer Source

Try to add a header to your request:

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;