gpt4 book ai didi

api - 为 POST 请求返回 200 Ok HTTP 状态是否正确?

转载 作者:可可西里 更新时间:2023-11-01 16:10:59 31 4
gpt4 key购买 nike

通常,我们在服务器端使用POST创建资源。
因此,理想情况下,如果一切正常,服务器应响应 201 Created HTTP 状态,或者在异步操作的情况下响应 202 Accepted HTTP 状态。

POST 请求是否可以返回 200 OK HTTP 状态?
或者我们不应该对 POST 请求使用 200 OK HTTP 状态?

最佳答案

我认为 200 是对 Internet 上 POST 请求的一种非常常见的响应。用着就好。

来自 RFC 7231 :

6.3.1. 200 OK

The 200 (OK) status code indicates that the request has succeeded.The payload sent in a 200 response depends on the request method.
For the methods defined by this specification, the intended meaning
of the payload can be summarized as:

GET a representation of the target resource;

HEAD the same representation as GET, but without therepresentationdata;

POST a representation of the status of, or results obtained from,the action;

PUT, DELETE a representation of the status of the action;

OPTIONS a representation of the communications options;

TRACE a representation of the request message as received by theendserver.

以及第 4.3.3 节:

Responses to POST requests are only cacheable when they includeexplicit freshness information (see Section 4.2.1 of [RFC7234]).However, POST caching is not widely implemented. For cases where anorigin server wishes the client to be able to cache the result of aPOST in a way that can be reused by a later GET, the origin server MAYsend a 200 (OK) response containing the result and a Content-Locationheader field that has the same value as the POST's effective requestURI (Section 3.1.4.2).

关于api - 为 POST 请求返回 200 Ok HTTP 状态是否正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42464409/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com