Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当添加对象的 POST 方法失败时,我应该返回哪个 HttpStatusCode?
这可能是由于数据库连接问题、代码错误、无效数据或任何其他原因。
这取决于它失败的原因。如果由于客户端做错了什么而失败(即尝试发布重复的数据,或尝试发布格式不正确的数据),那么您应该使用 400(在一些特殊情况下,您可能会使用特定的 4xx)。如果这是您的服务器代码中的错误(意外异常或 ASSERT 失败),那么您应该使用 500。有关 HTTP 状态代码及其含义的更多信息,请阅读规范。