断点续传原理 :http头 Range , Content-Range

断点续传,也就是要从文件已经下载的地方开始继续下载。在以前版本的 HTTP 协议是不支持断点的,HTTP/1.1 开始就支持了。一般断点下载时才用到 Range 和 Content-Range 实体头。

Range 

用于请求头中,指定第一个字节的位置和最后一个字节的位置,一般格式:

Range:(unit=first byte pos)-[last byte pos] 

Content-Range

用于响应头,指定整个实体中的一部分的插入位置,他也指示了整个实体的长度。在服务器向客户返回一个部分响应,它必须描述响应覆盖的范围和整个实体长度。一般格式: 

Content-Range: bytes (unit first byte pos) - [last byte pos]/[entity legth] 

一般下载请求:

    GET /test.txt HTTP/1.1  
    Accept:*/*  
    Referer:http://192.168.10.196  
    Accept-Language:zh-cn  
    Accept-Encoding:gzip,deflate  
    User-Agent:Mozilla/4.0(compatible;MSIE 6.0;Windows NT 5.2;.NET CLR 2.0.50727)  
    Host:192.168.10.196  
    Connection:Keep-Alive  

从256字节开始下载(加入了Range:bytes=256-)

    GET /test.txt HTTP/1.1  
    Accept:*/*  
    Referer:http://192.168.10.196  
    Accept-Language:zh-cn  
    Accept-Encoding:gzip,deflate  
    User-Agent:Mozilla/4.0(compatible;MSIE 6.0;Windows NT 5.2;.NET CLR 2.0.50727)  
    Host:192.168.10.196  
    Range:bytes=256-  
    Connection:Keep-Alive  
原文地址:https://www.cnblogs.com/birkhoff/p/5220357.html