在发出HTTP DELETE请求时,请求URI应该完全标识要删除的资源。但是,是否允许添加额外的元数据作为请求实体主体的一部分?
当前回答
也许下面的GitHUb url会帮助你,得到答案。 实际上,应用服务器,如Tomcat, Weblogic拒绝HTTP。带请求有效负载的DELETE调用。所以记住这些东西,我已经在github中添加了例子,请看看
https://github.com/ashish720/spring-examples
其他回答
对Body使用DELETE是有风险的…比起REST,我更喜欢这种列表操作方法:
常规操作
GET /objects/获取所有对象
GET /object/ID获取指定ID的对象
POST /objects添加一个新对象
PUT /object/ID添加指定ID的对象,更新对象
DELETE /object/ID删除指定ID的对象
所有自定义操作都是POST
POST /objects/addList添加body中包含的对象列表或数组
POST /objects/deleteList删除包含在body中的对象列表
POST /objects/customQuery基于body中的自定义查询创建一个List
如果客户不支持您的扩展操作,他们可以以常规方式工作。
如果有人在测试中遇到这个问题,不,它不是普遍支持的。
我目前正在用Sahi Pro进行测试,很明显,http DELETE调用剥离了任何提供的主体数据(根据端点设计批量删除的大量id列表)。
我已经和他们联系了几次,也把脚本、图片、日志三个包分开发给他们审核,他们还没有确认。一个失败的补丁,后来他们的支持缺席了电话会议,我仍然没有得到一个可靠的答案。
我确定Sahi不支持这个功能,而且我可以想象有许多其他的工具跟随套件。
在我看来,RFC 2616并没有规定这一点。
从第4.3节开始:
The presence of a message-body in a request is signaled by the inclusion of a Content-Length or Transfer-Encoding header field in the request's message-headers. A message-body MUST NOT be included in a request if the specification of the request method (section 5.1.1) does not allow sending an entity-body in requests. A server SHOULD read and forward a message-body on any request; if the request method does not include defined semantics for an entity-body, then the message-body SHOULD be ignored when handling the request.
9.7节:
The DELETE method requests that the origin server delete the resource identified by the Request-URI. This method MAY be overridden by human intervention (or other means) on the origin server. The client cannot be guaranteed that the operation has been carried out, even if the status code returned from the origin server indicates that the action has been completed successfully. However, the server SHOULD NOT indicate success unless, at the time the response is given, it intends to delete the resource or move it to an inaccessible location. A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not include an entity. If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those entries SHOULD be treated as stale. Responses to this method are not cacheable.c
因此,它没有显式地允许或禁止,并且代理可能会删除消息体(尽管它应该读取并转发它)。
实际答案:不
有些客户端和服务器会忽略甚至删除delete请求中的主体。在极少数情况下,它们会失败并返回错误。
值得注意的是,OpenAPI 3.0版本的规范放弃了对带体的DELETE方法的支持:
请看这里和这里的参考资料
这可能会影响将来这些api的实现、文档或使用。
推荐文章
- 有没有REST api的命名规范指南?
- 什么是HTTP中的“406-不可接受的响应”?
- 最好的轻量级web服务器(只有静态内容)的Windows
- HTTP POST在Java中使用JSON
- 哪些HTTP方法与哪些CRUD方法相匹配?
- 使用HTML形式的PUT方法
- 如何转义哈希字符在URL
- RESTful服务中部分更新的最佳实践
- JAX-RS / Jersey如何自定义错误处理?
- 有没有办法在python中做HTTP PUT
- 我能在服务器端应用程序(PHP、Ruby、Python等)上读取URL的哈希部分吗?
- 如何POST表单数据与Spring RestTemplate?
- 什么是http头“X-XSS-Protection”?
- 在nodejs http中body在哪里。得到回应?
- Restful API服务