java - PUT 响应代码为 204

标签 java web-services rest

我的 PUT 和 POST 是相同的,所以我使用 PUT 操作。这里我需要在 PUT 成功时发送响应正文数据,例如将新数据插入 Cassandra 或更新现有记录。

那么,在这种情况下我应该使用什么响应代码..我使用代码 204 成功 PUT 响应正文,但在使用 POSTMAN 测试时它会自动转换为 200 代码。那么我应该在这里使用什么。

最佳答案

根据this :

If the target resource does not have a current representation and the PUT successfully creates one, then the origin server MUST inform the user agent by sending a 201 (Created) response. If the target resource does have a current representation and that representation is successfully modified in accordance with the state of the enclosed representation, then the origin server MUST send either a 200 (OK) or a 204 (No Content) response to indicate successful completion of the request.

基于此(并同意 Hank 的观点),如果您的响应有实体,则应使用 201

关于java - PUT 响应代码为 204,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37019736/

相关文章:

java - mongodb BSON对象错误

java - 使用 Jersey 加密 RESTful 服务的数据

java - 与具有路径变量的单个端点相比,拥有单独的端点是否有优势?

java - 在android中加载文件

java - 创建自定义 hibernate 查询

java - 具有多行文本和动态高度的 Swing JList

java - 如何从 soap web 服务检索未知的 XML 并使用 java 插入数据库

java - 当分子是二的幂的倍数时加速除法和余数

c# - Web 服务应该返回 json

wcf - WCF 服务的 REST/SOAP 端点