角$ http.delete返回错误422(无法处理的实体) [英] Angular $http.delete returns error 422 (Unprocessable Entity)
问题描述
当我的网页尝试调用DELETE-rest方法时,出现了前端问题.但是,有趣的是,当我使用SoapUI进行SAME调用时,后端可以完美地工作.这是我的函数调用:
I am getting this frontend issue when my webpage tries to call a DELETE-rest method. But, the fun part is the backend works perfectly when I do the SAME call but using SoapUI. Here's my function call:
$scope.remove = function (id) {
var delUrl = "http://localhost:8080/secure/regulations/" + id;
$http.delete(delUrl);
}
该Web服务类似于 secure/regulations/{id} ,并且不给出任何答案(仅执行删除操作),正如我所说,SoapUI调用就像一个超级按钮一样工作,但是这个在浏览器中没有功能.在标题下方:
The web service is like secure/regulations/{id}, and give no answer (just do a delete), and as I said, a SoapUI call works like a charm, but a this function in the browser doesn't. 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/
深入了解后端的功能,当它对数据库执行 get(id)时(在此之前, id 具有价值),就会出现问题,但是我不相信SoapUI可以解决问题.前端代码:S
Taking a deep look in the backend's function, the problem raises when it does a get(id) against the database (before that point, id has value), but I resist to believe that the problem is there if SoapUI works. Something may be missed at frontend code :S
编辑:在SoapUI中,请求 raw 如下:
EDIT: In SoapUI, request raw is the following:
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)
根本没有标题(在 headers 标签中),但是在 Representations 中没有空的 Media-Type:application/json (自动创建).
There is no headers at all (in headers tab), but in Representations there is an empty Media-Type: application/json (autocreated).
真诚地感谢您的帮助!
推荐答案
尝试使用带有类似于SoapUI请求的额外标头的调试详细版本:
Try using this debug-verbose version with extra header similar to 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);
});
}
这篇关于角$ http.delete返回错误422(无法处理的实体)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!