且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如果POST成功但未创建任何新内容,我们应该返回什么状态代码?

更新时间:2023-12-05 11:10:46

303怎么样-参见其他"?似乎适合.我提请您注意这句话
摘自 https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

How about 303 - See Other? Seems to fit. I draw your attention to this sentence
from the spec at https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

此方法主要用于允许POST激活的脚本的输出将用户代理重定向到选定的资源.

This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource.

这听起来像是您想对我做的事情.剩下的就是这个.

That sounds like what you want to do to me. Here's the rest of it.

10.3.4 303查看其他

10.3.4 303 See Other

可以在不同的URI下找到对请求的响应,并且应该使用该资源上的GET方法来检索该请求.存在此方法主要是为了允许POST激活的脚本的输出将用户代理重定向到选定的资源.新URI不能替代原始请求的资源.303响应一定不能被缓存,但是对第二个(重定向的)请求的响应可能是可缓存的.

The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource. The new URI is not a substitute reference for the originally requested resource. The 303 response MUST NOT be cached, but the response to the second (redirected) request might be cacheable.

应在响应中的位置"字段中指定不同的URI.除非请求方法是HEAD,否则响应的实体应包含简短的超文本注释,并带有指向新URI的超链接.

The different URI SHOULD be given by the Location field in the response. Unless the request method was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s).

  Note: Many pre-HTTP/1.1 user agents do not understand the 303
  status. When interoperability with such clients is a concern, the
  302 status code may be used instead, since most user agents react
  to a 302 response as described here for 303