开发者

HttpDelete request with JSON payload in Android

I need to call a web service to delete data, and I need to do it using HttpDelete. The service takes a JSON object as parameter.

I have done HttpPost before, using SetEntity, but this is not available with HttpDelete.

It's a call like 开发者_C百科http://url/DELETE/service and something like { id: "xxxxxxx", id2: 11 } as parameter.

I can't find any good info on this. Any ideas?


You can not send a body in a HTTP DELETE request.

If you need to do that, there is probably something wrong with your REST design.

Why not http://url/srvice/xxxxxx/11 instead of http://url/DELETE/service with a body ?


RFC2616 doesn't specify anything about a entity on an HTTP DELETE request. I would say your best bet is to pass the values you need in the path of your request.

http: //url/DELETE/service/xxxxxx/11


The id is most likely passed in the url OR possibly could be passed in a header value. Here's an example:

HttpDelete httpdelete = new HttpDelete(targetURL);                              
httpdelete.setHeader("id",id);  // If not in the url, this could be where the id is set.


There are use cases when this would be awesome. One I'm running into now is a need for a "bulk delete". Basically, for efficiency reasons, deleting one entry at a time is way slower than it would be to delete multiple entries at once. I'm forced to use POST and be un-RESTful. In my opinion, this is a design flaw in REST, or at least a design limitation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜