Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the "Content-Length" field in HTTP header?

Tags:

http-headers

What does it mean?

  1. Byte count of encoded content string with encoding specified in header.
  2. Character count of content string.

Especially in case of Content-Type: application/x-www-form-urlencoded.

like image 688
eonil Avatar asked May 05 '10 13:05

eonil


People also ask

Does Content-Length include headers?

The Content-Length header is a number denoting an the exact byte length of the HTTP body. The HTTP body starts immediately after the first empty line that is found after the start-line and headers.

What is the use of Content-Length?

HTTP Content-Length entity-header is used to indicate the size of entity-body in decimal no of octets i.e. bytes and sent it to the recipient. It is a forbidden header name. Basically it is the number of bytes of data in the body of the request or response. The body comes after the blank line below the headers.

What is the Content-Type in header of HTTP?

The Content-Type representation header is used to indicate the original media type of the resource (prior to any content encoding applied for sending). In responses, a Content-Type header provides the client with the actual content type of the returned content.

How do I find the Content-Length of an HTTP?

<? php print_r($_POST) ; ?>


3 Answers

It's the number of bytes of data in the body of the request or response. The body is the part that comes after the blank line below the headers.

like image 60
Tom Cabanski Avatar answered Oct 18 '22 21:10

Tom Cabanski


rfc2616

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.

It doesn't matter what the content-type is.

Extension at post below.

like image 27
WhirlWind Avatar answered Oct 18 '22 20:10

WhirlWind


The Content-Length header is a number denoting an the exact byte length of the HTTP body. The HTTP body starts immediately after the first empty line that is found after the start-line and headers.

Generally the Content-Length header is used for HTTP 1.1 so that the receiving party knows when the current response* has finished, so the connection can be reused for another request.

* ...or request, in the case of request methods that have a body, such as POST, PUT or PATCH

Alternatively, Content-Length header can be omitted and a chunked Transfer-Encoding header can be used.

If both Content-Length and Transfer-Encoding headers are missing, then at the end of the response the connection must be closed.

The following resource is a guide that I found very useful when learning about HTTP:

HTTP Made Really Easy.

like image 42
spender Avatar answered Oct 18 '22 20:10

spender