我正在实现一个 API。 API 接受/返回 JSON 内容类型。 现在,假设某些 POST 请求提交的数据无效,例如缺少属性,或者相同数据存在重复。 在这种情况下,标准 HTML 响应代码是什么?
最佳答案
错误发生在客户端,因此您需要使用4xx状态码。我会选择 400 - Bad Request :
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
关于web-services - 发生验证错误时的响应代码应该是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4058708/