http-headers - 如果缺少必需的 header ,返回的最合适的 HTTP 状态代码是什么?

标签 http-headers http-status-codes http-status-code-403 http-status-code-400

我读了 What HTTP status response code should I use if the request is missing a required parameter?但它没有具体询问标题,似乎也没有达成共识。

此问题的上下文假设身份验证成功。我目前偏爱 400(尽管这感觉不对,因为这并不是真正的“语法错误”)或 403。鉴于 403 的描述:

The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity.



这对我来说最有意义。

有人可以启发我吗?谢谢。

最佳答案

400 错误请求

这是请求中的用户错误。与 403 不同,应该允许客户端重复他们的请求,但只能在修改后:

10.4.1 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.



编辑

正如马克里德在评论中指出的那样,403 说,“你发送给我的内容没有任何问题。你有适当的授权,语法是有效的。我只是不想按照你的要求去做。”

粗体部分只是说,如果服务器选择这样做,它可以确切地告诉客户端它不想满足请求的原因。

关于http-headers - 如果缺少必需的 header ,返回的最合适的 HTTP 状态代码是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10576898/

相关文章:

php - 什么可能导致标题已经发送,我将如何追踪它?

python - 检索 Python 服务器端设置的 cookie

http - 为什么基于主机 header 路由请求是代理流量的好方法?

http - HTTP OPTIONS 请求可以返回 204 还是应该始终返回 200?

asp.net-mvc - 为什么我收到消息 "The specified request cannot be executed from current Application Pool"?

web-applications - 正确使用HTTP错误代码。 550-为什么是5xx而不是4xx?

java - 如何让 Apache Tomcat 接受 DELETE 方法

c# - 从对 HttpWebRequest 的调用中复制 HTTP 请求/响应 header ?

javascript - 为什么我被 403 禁止?

javascript - 对于大小超过 ~1MB 的文件,Github.js getSha 出现 403 错误