---
title: "Chunked transfer encoding"
author: "netbean77"
date: "2011-09-15T12:53:44Z"
tags: []
categories: ["Web前端"]
slug: "chunked-transfer-encoding"
draft: false
lastmod: "2011-09-15T12:53:44Z"
id: 1172430
url: "https://netbean77.iteye.com/blog/1172430"
---

Chunked transfer encoding是http1.1中的一种数据传输机制。

 

refer:

 

**Chunked transfer encoding** is a data transfer mechanism in version 1.1 of the [Hypertext Transfer Protocol](http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol "Hypertext Transfer Protocol") (HTTP) in which a [web server](http://en.wikipedia.org/wiki/Web_server "Web server") serves content in a series of chunks. It uses the [Transfer-Encoding](http://en.wikipedia.org/wiki/List_of_HTTP_header_fields#transfer-encoding-response-header "List of HTTP header fields") HTTP response header in place of the [Content-Length](http://en.wikipedia.org/wiki/Content-Length "Content-Length") header, which the protocol would otherwise require. Because the Content-Length header is not used, the server does not need to know the length of the content before it starts transmitting a response to the [client](http://en.wikipedia.org/wiki/Client_%28computing%29 "Client (computing)") (usually a [web browser](http://en.wikipedia.org/wiki/Web_browser "Web browser")). Web servers can begin transmitting responses with dynamically-generated content before knowing the total size of that content.

The size of each chunk is sent right before the chunk itself so that a client can tell when it has finished receiving data for that chunk. The data transfer is terminated by a final chunk of length zero.

 

example:

```
HTTP/1.1 200 OK
Content-Type: text/plain
Transfer-Encoding: chunked

25
This is the data in the first chunk

1C
and this is the second one

3
con
8
sequence
0
```