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

发布于 2024-11-18 12:38:34 字数 49 浏览 3 评论 0原文

我假设响应代码 200 始终允许响应主体,但我找不到任何明确提及删除请求的响应主体。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

双马尾 2024-11-25 12:38:34

RFC 中明确提到了这

一点答案是:

如果您返回200,您应该包含一个响应正文,其中包含描述已删除项目/资源的实体。

202 类似于异步请求/响应返回状态。

204 明确表示您不包含响应正文

It is explicitly mentioned here in the RFC

The short answer is:

You should include a response body with an entity describing the deleted item/resource if you return 200.

202 is something like an asynchronous request/response return status.

204 says explicitly that you do not include a response body

风筝有风,海豚有海 2024-11-25 12:38:34

是的,根据W3C 规范:

9.7 删除

DELETE 方法要求
源服务器删除资源
由请求 URI 标识。这
方法可能会被人类覆盖
干预(或其他方式)
源服务器。客户不能是
保证操作已经完成
已执行,即使状态代码
从源服务器返回
表示该操作已
成功完成。然而,
服务器不应该指示成功
除非,当时的响应是
鉴于,它打算删除
资源或将其移动到无法访问的位置
位置。

成功的响应应该是 200
(好的)如果响应包含
描述状态的实体,202
(已接受)如果尚未采取行动
已颁布,或 204(无内容),如果
该行动已颁布,但
响应不包含实体。

如果请求通过缓存
Request-URI 标识一个或
更多当前缓存的实体,那些
条目应该被视为过时的。
对此方法的响应不是
可缓存。

Yes, you should usually respond with a 200 response code as per the W3C spec:

9.7 DELETE

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文