http - 内容长度与实际内容长度不匹配的适当 HTTP 状态代码是什么

标签 http http-headers

我知道缺少 content-length header 是 411,但不确定当 content-length 中给出的值与实际内容长度不匹配时我应该如何响应

最佳答案

标准似乎没有提及响应的实际代码,只是两个长度必须匹配并且 HTTP/1.1 代理必须通知用户。

我只会使用 400 Bad Request 代码,因为毕竟那是问题所在(违反标准的请求)并且其他 400 系列代码似乎都不够接近匹配。 x00 代码还定义了状态的,因此可用于通用代码。

请记住,代码是可扩展的,您始终可以定义自己的代码,并且无论如何都需要不识别它的代理将其视为 x00 变体(第 6.1.1 节) RFC2616):

HTTP status codes are extensible. HTTP applications are not required to understand the meaning of all registered status codes, though such understanding is obviously desirable. However, applications MUST understand the class of any status code, as indicated by the first digit, and treat any unrecognized response as being equivalent to the x00 status code of that class, with the exception that an unrecognized response MUST NOT be cached. For example, if an unrecognized status code of 431 is received by the client, it can safely assume that there was something wrong with its request and treat the response as if it had received a 400 status code. In such cases, user agents SHOULD present to the user the entity returned with the response, since that entity is likely to include human- readable information which will explain the unusual status.

关于http - 内容长度与实际内容长度不匹配的适当 HTTP 状态代码是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6287154/

相关文章:

android - Volley - 阻塞方式的http请求

objective-c - 删除 NSMutableURLRequest 中的 HTTP header

http-headers - HEAD 请求收到 "403 forbidden"而 GET "200 ok"?

node.js - 在 firebase 中看不到请求 header 的值?

javascript - 带有 Content-Disposition 的 HTTP 响应不会触发下载

http - HTTP header 设置问题

c++ - 基本 C++ 套接字编程中的异常 HTTP 响应

http - 为 HTTP 客户端设置代理

java - 对 Bitbucket API 的 HTTP PUT 请求

http - 我应该使用哪些 HTTP 客户端 header 来指示代理从源重新获取并缓存响应?