这是什么意思?

头中指定编码的已编码内容字符串的字节数。 内容字符串的字符数。

特别是在Content-Type: application/x-www-form-urlencoded的情况下。


当前回答

一个八位是8位。Content-length是消息体所代表的字节数。

其他回答

根据说明书:

The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET. Content-Length = "Content-Length" ":" 1*DIGIT An example is Content-Length: 3495 Applications SHOULD use this field to indicate the transfer-length of the message-body, unless this is prohibited by the rules in section 4.4. Any Content-Length greater than or equal to zero is a valid value. Section 4.4 describes how to determine the length of a message-body if a Content-Length is not given. Note that the meaning of this field is significantly different from the corresponding definition in MIME, where it is an optional field used within the "message/external-body" content-type. In HTTP, it SHOULD be sent whenever the message's length can be determined prior to being transferred, unless this is prohibited by the rules in section 4.4.

考虑一下你是否有这样的标题:

content-encoding: gzip
content-length: 52098
content-type: text/javascript; charset=UTF-8

内容长度是压缩消息体的大小,以“八位”为单位(即以8位为单位,这恰好是所有现代计算机的“字节”)。

实际消息体的大小可以是其他大小,可能是150280字节。

字符的数量也可以不同,可能是150231个字符,因为一些unicode字符使用多个字节(注意UTF-8是一种标准编码)。

所以,不同的数字取决于你是否关心有多少数据被传输,或者有多少数据被保存,或者有多少符号被看到。当然,不能保证会提供这些头文件。

从这里开始:

The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET. Content-Length = "Content-Length" ":" 1*DIGIT An example is Content-Length: 3495 Applications SHOULD use this field to indicate the transfer-length of the message-body, unless this is prohibited by the rules in section 4.4. Any Content-Length greater than or equal to zero is a valid value. Section 4.4 describes how to determine the length of a message-body if a Content-Length is not given. Note that the meaning of this field is significantly different from the corresponding definition in MIME, where it is an optional field used within the "message/external-body" content-type. In HTTP, it SHOULD be sent whenever the message's length can be determined prior to being transferred, unless this is prohibited by the rules in section 4.4.

我的解释是,这意味着“导线上”的长度,即“编码”内容的长度

从本页

The most common use of POST, by far, is to submit HTML form data to CGI scripts. In this case, the Content-Type: header is usually application/x-www-form-urlencoded, and the Content-Length: header gives the length of the URL-encoded form data (here's a note on URL-encoding). The CGI script receives the message body through STDIN, and decodes it. Here's a typical form submission, using POST: POST /path/script.cgi HTTP/1.0 From: frog@jmarshall.com User-Agent: HTTPTool/1.0 Content-Type: application/x-www-form-urlencoded Content-Length: 32

Content-Length报头是一个数字,表示HTTP正文的确切字节长度。HTTP主体在开始行和报头之后的第一个空行之后立即开始。

通常,Content-Length报头用于HTTP 1.1,以便接收方知道当前响应*何时结束,这样连接就可以用于另一个请求。

*……或请求,在请求方法有一个主体的情况下,如POST, PUT或PATCH

或者,可以省略Content-Length头,使用分块的Transfer-Encoding头。

如果Content-Length和Transfer-Encoding头都缺失,则在响应的末尾必须关闭连接。

以下资源是我在学习HTTP时发现的非常有用的指南:

HTTP变得非常简单。