用于更新和删除的 HTTP 状态代码?

标签 http http-status-codes

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

最佳答案

对于PUT 请求:HTTP 200HTTP 204 应该意味着“资源更新成功”。 HTTP 201 如果 PUT 请求创建了新资源。

对于DELETE 请求:HTTP 200HTTP 204 应表示“资源已成功删除”。

HTTP 202 也可以通过任一操作返回,这意味着该指令已被服务器接受,但尚未完全应用。操作稍后可能会失败,因此客户端不应完全假设操作成功。

客户端收到它无法识别的状态代码,但它以 2 开头,应将其视为 200 OK。

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.

来源:IETF: RFC-9110 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

来源:List of HTTP status codes: 2xx Success

关于用于更新和删除的 HTTP 状态代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2342579/

相关文章:

forms - 防止重新提交表单

java - 多个完整的 HTTP 请求卡在 TCP CLOSE_WAIT 状态

java - 如何转发 HTTP 响应

http-status-codes - `HTTP/1.1` 响应返回 HTTP 状态代码 `421 Misdirected Request` 是否有意义?

ASP.NET/IIS 远程调试 - DEBUG 动词

node.js - 从 Node.js 发出网络请求时如何指定网络接口(interface)?

google-app-engine - 部署在 Google App Engine 上的测试服务器

rest - 何时使用 HTTP 状态码 425 "Too Early"

不受支持的浏览器的 HTTP 状态代码

c++ - HTTP 状态码到 HRESULT 的映射