Android 中带有 JSON 负载的 HttpDelete 请求
我需要调用 Web 服务来删除数据,并且需要使用 HttpDelete 来完成此操作。该服务采用 JSON 对象作为参数。
我之前使用 SetEntity 完成了 HttpPost,但这不适用于 HttpDelete。
这是一个类似 http://url/DELETE/service 的调用,以及类似 { id: "xxxxxxx" , id2: 11 }
作为参数。
我找不到这方面的任何好的信息。有什么想法吗?
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 http://url/DELETE/service and something like { id: "xxxxxxx", id2: 11 }
as parameter.
I can't find any good info on this. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您无法在 HTTP DELETE 请求中发送正文。
如果您需要这样做,则您的 REST 设计可能有问题。
为什么不使用
http://url/srvice/xxxxxx/11
而不是带有 body 的http://url/DELETE/service
?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 ofhttp://url/DELETE/service
with a body ?RFC2616 未在 HTTP DELETE 请求上指定有关实体的任何信息。我想说你最好的选择是在你的请求路径中传递你需要的值。
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.
id 很可能在 url 中传递,或者可能在标头值中传递。这是一个例子:
The id is most likely passed in the url OR possibly could be passed in a header value. Here's an example:
在某些用例中这会很棒。我现在遇到的一个问题是需要“批量删除”。基本上,出于效率原因,一次删除一个条目比一次删除多个条目慢得多。我被迫使用 POST 并且不 RESTful。在我看来,这是 REST 的一个设计缺陷,或者至少是一个设计限制。
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.