简体   繁体   English

HTTP状态码返回

[英]Http status code return

如果用户的发帖请求正确但数据库中没有任何更新,因为用户正在为数据库中已经存在的每个字段发送相同的值,应该向用户发送什么HTTP状态代码?

A 200 status would definitely be perfectly appropriate in this case. 在这种情况下,200个身份绝对是非常合适的。

What you are describing is usually something that an application on top of the HTTP-based API would handle/add as context. 您所描述的通常是基于HTTP的API之上的应用程序将作为上下文处理/添加的内容。

One lesser-known status code which could be used in such cases, however, is 204. 但是,在这种情况下可以使用的一种鲜为人知的状态代码是204。

"The 204 (No Content) status code indicates that the server has successfully fulfilled the request and that there is no additional content to return in the response payload body" “ 204(无内容)状态码表示服务器已成功满足请求,并且响应有效内容正文中没有其他要返回的内容”

In other words, depending on your application's setup, you could use a 204 (with no response body) to indicate that the PUT/update request itself was successful. 换句话说,根据应用程序的设置,您可以使用204(不带响应主体)表示PUT /更新请求本身已成功。 but that nothing was modified. 但是没有任何修改。

See here for further reading on 204: http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-19#section-7.2.5 有关204的更多信息,请参见此处: http : //tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-19#section-7.2.5

You will use 204 in this case. 在这种情况下,您将使用204。

The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. 服务器已满足请求,但不需要返回实体,可能要返回更新的元信息。 The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant. 响应可以包括实体标题形式的新的或更新的元信息,如果存在,则应与所请求的变量相关联。

If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. 如果客户端是用户代理,则不应更改导致发送请求的文档视图。 This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view. 尽管任何新的或更新的元信息都应该应用于当前在用户代理的活动视图中的文档,但该响应主要旨在允许输入操作而不会导致更改用户代理的活动文档视图。

The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields. 204响应必须不包含消息正文,因此始终由标头字段之后的第一个空行终止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM