Angular $ http.delete returns error 422 (Non-Processable Entity)

I am getting this external question when my web page tries to call the DELETE-rest method. But, the fun part is the backend works great when I do SO SOUND, but using SoapUI. Here's my function call:

$scope.remove = function (id) {
     var delUrl = "http://localhost:8080/secure/regulations/" + id;
     $http.delete(delUrl);
}

      

The webservice is like secure / rules / {id} and gives no response (just do a delete) and as I said, the SoapUI call works like a charm, but this function in the browser does not, Here below the headers:

General
Remote Address:127.0.0.1:8080
Request URL:http://localhost:8080/secure/regulations/4
Request Method:DELETE
Status Code:422 Unprocessable Entity

Response Headers
Content-Type:application/json;charset=UTF-8
Date:Tue, 23 Jun 2015 14:28:00 GMT
Server:Apache-Coyote/1.1
Transfer-Encoding:chunked

Request Headers
Accept:application/json, text/plain, *\/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:__ngDebug=true
Host:localhost:8080
Origin:http://localhost:8080
Referer:http://localhost:8080/secure/

      

Taking a close look at the backend function, the problem occurs when it gets a get (id) against the database (up to this point, id matters), but I can't believe the problem exists if SoapUI is working. Something might be missing in the outer code: S

EDIT : In SoapUI, the raw request is as follows:

DELETE http://localhost:8080/secure/regulations/5 HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/json
Content-Length: 0
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

      

There are no headers at all (in the headers tab), but the views have an empty Media-Type: application / json (auto-registered).

Any help is honestly appreciated!

+3


source to share


1 answer


Try using this version of debug-verbose with an extra header similar to the SoapUI request:



$scope.remove = function (id) {
    var delUrl = "http://localhost:8080/secure/regulations/" + id;
    var _delete = {
         'method': 'DELETE',
         'url': delUrl,
         'headers': {
             'Content-Type': 'application/json'
         },
         'data': ""
    }

    $http(_delete)
        .success(function(){
            console.log("OK");
        })
        .error(function(data, status, headers, config){
            console.log(data);
            console.log(status);
            console.log(headers);
            console.log(config);
        });
}

      

+1


source







All Articles