我在想 412(前提条件失败),但可能有更好的标准?
最佳答案
基于 spec,状态 422 似乎最合适.
The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions. For example, this error condition may occur if an XML request body contains well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions.
他们指出格式错误的 xml 是错误语法的一个示例(需要 400)。格式错误的查询字符串似乎与此类似,因此 400 似乎不适合缺少参数的格式正确的查询字符串。
注意:由于上面的 RFC 是关于 WebDAV 的,因此可能会有一种误解,认为 422 和其他一些只能在 WebDAV 的上下文中使用,而在 WebDAV 之外使用它们是“非标准的”。但这仅意味着这些状态代码是在本 RFC 的上下文中引入的。事实上,这些定义的措辞是经过精心选择的,并非特定于 WebDAV。
关于http - 如果请求缺少必需参数,我应该使用什么 HTTP 状态响应代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3050518/