The problem of content-length and Transfer-Encoding: chunked in the http return header


Usually, the HTTP protocol uses the Content-Length header to inform the length of the data. Then, in the process of data downlink, the Content-Length method needs to cache all the data in the server in advance, and then send all the data to the client in one go.

If you want to generate data and send it to the client at the same time, the WEB server needs to use "Transfer-Encoding: chunked" instead of Content-Length.

When using Transfer-Encoding: chunked, the actual length of the transfer will be placed in the first line of the actual content. As shown in the screenshot above, 36 is the actual length, but this number is in hexadecimal .

The last number 0 should be the end. If there is no 0\r\n\r\n to end the chunked, the parsing will fail.


? ? I don't know if my understanding is correct? ?

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325906190&siteId=291194637