更新和删除的 HTTP 状态码?

编程入门 行业动态 更新时间:2024-10-08 06:17:16
本文介绍了更新和删除的 HTTP 状态码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我应该为UPDATE(PUT)和DELETE(例如产品成功更新)设置什么状态码?

解决方案

对于 PUT 请求:HTTP 200 或 HTTP 204 应该暗示资源更新成功".

对于 DELETE 请求:HTTP 200 或 HTTP 204 应该暗示资源删除成功".HTTP 202 也可以返回,这意味着该指令已被服务器接受并且资源已标记为删除".

PUT

如果现有资源被修改,则应发送 200(OK)或 204(无内容)响应代码以指示请求成功完成.

删除

如果响应包含描述状态的实体,则成功响应应该是 200(OK),如果操作尚未执行,则为 202(已接受),如果操作已执行但响应为 204(无内容)不包括实体.

来源:W3:HTTP/1.1 方法定义

HTTP 200 OK:成功 HTTP 的标准响应要求.实际反应将取决于所使用的请求方法.

HTTP 204 No Content:服务器成功处理了请求,但没有返回任何内容

来源:HTTP 状态代码列表:2xx 成功

What status code should I set for UPDATE (PUT) and DELETE (e.g. product successfully updated)?

解决方案

For a PUT request: HTTP 200 or HTTP 204 should imply "resource updated successfully".

For a DELETE request: HTTP 200 or HTTP 204 should imply "resource deleted successfully". HTTP 202 can also be returned which would imply that the instruction was accepted by the server and the "resource was marked for deletion".

PUT

If an existing resource is modified, either the 200 (OK) or 204 (No Content) response codes SHOULD be sent to indicate successful completion of the request.

DELETE

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.

Source: W3: HTTP/1.1 Method Definitions

HTTP 200 OK: Standard response for successful HTTP requests. The actual response will depend on the request method used.

HTTP 204 No Content: The server successfully processed the request, but is not returning any content

Source: List of HTTP status codes: 2xx Success

更多推荐

更新和删除的 HTTP 状态码?

本文发布于:2023-10-10 18:06:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479335.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:新和   状态   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!