简体   繁体   English

为什么在HTTP DELETE请求中包含实体主体不是一个好习惯?

[英]Why is not a good practice to have an entity body in a HTTP DELETE request?

I am working with Restful Web Services using Java and JAX-RS and I came across the issue of sending a DELETE request with an entity body. 我正在使用JavaJAX-RS使用Restful Web Services ,并且遇到了使用实体正文发送DELETE请求的问题。

I spent a couple of hours looking for a way to send a DELETE request with a message in the body but the only thing that I found was a work around using the Apache HttpClient . 我花了几个小时来寻找一种发送带有正文中消息的DELETE请求的方法,但是我发现的唯一发现就是使用Apache HttpClient的工作

Some of the answers I found are saying that it does not make sense to have a body in DELETE requests and as I see it many servers are supporting this by not allowing a DELETE with body. 我发现的一些答案是说,在DELETE请求中包含主体是没有意义的,而且正如我所见,许多服务器通过不允许使用body进行DELETE来支持这一点。 eg " entity enclosing DELETE requests make no sense " 例如:“ 包含DELETE请求的实体没有意义

So my question is why it is not a good practice to have a body in a DELETE request? 所以我的问题是,为什么在DELETE请求中包含主体不是一种好习惯? What is the drawback on this? 这有什么缺点?

Thanks 谢谢

The DELETE method requests that the origin server delete the resource identified by the Request-URI. DELETE方法请求原始服务器删除由Request-URI标识的资源。 and every resource on web server is identified by only URI. 并且Web服务器上的每个资源仅由URI标识。 thats why it does not make sense to have body in DELETE 多数民众赞成在为什么删除身体没有意义

REST is noisy, and it is likely that a separate DELETE call for each resource was the intent. REST嘈杂,很可能是针对每个资源的单独DELETE调用。 For a limited number of ids, you could use a query param on the collection resource: 对于有限数量的ID,可以在集合资源上使用查询参数:

DELETE /widgets?id=1,2,4,16,256

In general, you should be able to use query params as filters on a DELETE of a collection just like you would on a GET of that collection. 通常,您应该能够在集合的DELETE上使用查询参数作为过滤器,就像对该集合的GET一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将HTTP DELETE请求实体主体映射到方法参数 - Mapping an HTTP DELETE request entity body to a method parameter HTTP删除与请求正文问题 - HTTP Delete with Request Body issues 为什么在 JSON 负载请求正文中发送 http 请求元数据被认为是不好的做法,而最好使用请求标头? - Why is it considered bad practice to send http request meta data in the JSON payload request body itself, while preferable to use request header? spring http请求映射单个uri用不同的请求参数到不同的方法是好的做法还是不好的做法 - spring http request mapping single uri with different request parameters to different method is good practice or bad practice DELETE HTTP 请求参数和请求体的区别 - Difference between DELETE HTTP request parameters and request body 为什么阅读 HTTP 请求的响应正文很重要? - Why is it important to read the response body of an HTTP request? Spring Web MVC:HTTP DELETE不再有请求体 - Spring Web MVC: no request body possible for HTTP DELETE anymore 如何使用AsyncHttpClient使用JSON编码主体构建HTTP DELETE请求 - How to build HTTP DELETE request with JSON encoded body using AsyncHttpClient 在二传手中修剪是否是个好习惯? - Is it a good practice to have trim in setter? 让所有类都具有继承性是一种好习惯吗 - Is it good practice to have all classes to have inheritence
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM