http - 如果请求缺少必需参数,我应该使用什么 HTTP 状态响应代码?

标签 http http-status-codes

我在想 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/

相关文章:

http - 在 Angular2 中扩展 HTTP 模块会抛出错误

c# - 在 HTTP 客户端中使用公共(public)代理服务器

HTTP 状态代码 : differentiating between being over capacity and being down for maintenance

http - 调用 http.ResponseWriter.Write() 时检查错误

http - 与 text/plain ContentType 一起使用的正确换行符是什么?

Android Https 状态码 -1

ios - NSErrorDomain 用于打包 HTTP 结果代码?

http - 当 REST API 用户尝试访问对象并且出现错误时,使用哪个 HTTP 状态代码?

http - 修改与 HTTP 状态代码一起发送的文本是否可以接受?

r - 如何在 R 中通过网络检测远程文件夹中新添加的文件?