Source:
http://blog.csdn.net/superhosts/article/details/8737434
http://bbs.csdn.net/topics/390384017
There are two main ways to verify the length of the content that the request for HTTP returns results:
1. When the client is in the HTTP header (head) plus connection:keep-alive, the server's response is the form of transfer-encoding:chunked, notifying the page that the data has been received. For example, a long connection or a program can be dynamically output content, for example, some operations are complex and require the user to get the latest results in a timely manner, then use chunked encoding content chunked output.
2. Except as described in 1, it is generally possible to obtain content-length.
Content-length If it exists and is valid, it must be exactly the same as the transmission length of the message content . (After testing, if it is too short, it is truncated and too long results in a timeout.) )
If there is a transfer-encoding (with emphasis on chunked), there can be no content-length in the header, and there will be neglect.
-----------------------------------------------------------------------------------------------------
Transfer-encoding:chunked means: While reading the data, it is sent to the client side. Not a second transmission. will take this header message.
Content-length: That is, the server has been cached in which to say, the message sent to the client will take this header information.
This is the case, the server is dynamically generated, you when the data is very small, not exceeding the buffer size of the servers
The header of HTTP has not been transmitted and can transmit the content-length.
In cases where the size of the data exceeds buffer, the server must flush the HTTP header and entity (data) to the client, at which point the entity size is still unknown, so there is no content-length.
Content-length and Transfer-encoding in the HTTP protocol response header