我的 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/