简体   繁体   English

HTTP-DELETE 请求是否允许响应体?

[英]Is a response-body allowed for a HTTP-DELETE-request?

I assume the response code 200 always allows for a response-body, but I can't find any explicit mention of response-bodies for DELETE-requests.我假设响应代码 200 始终允许响应体,但我找不到任何明确提及删除请求的响应体。

It is explicitly mentioned here in the RFC它在RFC中明确提到

The short answer is:简短的回答是:

You should include a response body with an entity describing the deleted item/resource if you return 200 .如果您返回200则应包含一个带有描述已删除项目/资源的实体的响应正文。

202 is something like an asynchronous request/response return status. 202类似于异步请求/响应返回状态。

204 says explicitly that you do not include a response body 204明确表示您不包括响应正文

Yes, you should usually respond with a 200 response code as per the W3C spec :是的,根据 W3C 规范,您通常应该使用 200 响应代码进行响应:

9.7 DELETE 9.7 删除

The DELETE method requests that the origin server delete the resource identified by the Request-URI. DELETE 方法请求源服务器删除由 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.如果响应包含描述状态的实体,则成功的响应应该是 200(OK),如果操作尚未制定,则为 202(已接受),或者如果操作已经制定但响应不包括,则应为 204(无内容)一个实体。

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.如果请求通过缓存并且 Request-URI 标识了一个或多个当前缓存的实体,那么这些条目应该被视为陈旧的。 Responses to this method are not cacheable.对此方法的响应不可缓存。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM