要实现HTTP断点续传,Web服务器必须支持HTTP/1.1(协议文本为RFC2068),当然也不是所有支持HTTP/1.1的服务器都实现了HTTP断点续传。一般在正常的Header之外,还要在Header中加上如下几句:
Connection: close
Host:
www.host.com Range: bytes=1-100
这里的Range就是指定下载范围,也可以使用"100-"表示从100开始下载。更详细的内容可以参见RFC2068。
QHttp *http = new QHttp(this);
QHttpRequestHeader header("GET", "xxxxx.zip");
header.setValue("Host", "www.xxx.com");
header.setValue("Referer", "http://www.xxx.com/img");
header.setValue("Accept", "*/*");
header.setValue("Pragma", "no-cache");
header.setValue("Cache-Control", "no-cache");
header.setValue("Range","bytes=1-100"); header.setValue("Connection","close");
http->setHost("www.xxx.com");
int ret = http->request(header);
请讨论能否下载xxxx.zip 的1至100个字节?