HTTP Content-Length

来自WHY42
Riguz留言 | 贡献2024年1月17日 (三) 11:28的版本
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

The Content-Length header indicates the size of the message body, in bytes, sent to the recipient.

Content-Length: <length>

The Content-Length header is not mandatory in HTTP responses, but it is recommended for responses that have a body. The header specifies the length of the message body in octets (8-bit bytes) and allows the recipient to accurately determine the message size and prevent buffer overflows. However, for responses that use chunked transfer encoding, the Content-Length header is not necessary, as the chunked encoding itself indicates the message length.

When no Content-Length is received, the client keeps reading until the server closes the connection.[1]