复制代码 代码如下:
GET /image/index_r4_c1.jpg HTTP/1.1
Accept: */*
Referer: :8080
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)
Host: 192.168.3.120:8080
Connection: Keep-Alive
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Tue, 24 Jun 2003 05:39:40 GMT
Content-Type: image/jpeg
Accept-Ranges: bytes
Last-Modified: Thu, 23 May 2002 03:05:40 GMT
ETag: "bec48eb862c21:934"
Content-Length: 2827
….
复制代码 代码如下:
GET /image/index_r4_c1.jpg HTTP/1.1
Accept: */*
Referer: :8080
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)
Host: 192.168.3.120:8080
Range:bytes=1024-
Connection: Keep-Alive
复制代码 代码如下:
HTTP/1.1 206 Partial Content
Server: Microsoft-IIS/5.0
Date: Tue, 24 Jun 2003 05:39:40 GMT
Content-Type: image/jpeg
Accept-Ranges: bytes
Last-Modified: Thu, 23 May 2002 03:05:40 GMT
ETag: "bec48eb862c21:934"
Content-Length: 1803
Content-Range: bytes 1024-1803/2827
复制代码 代码如下:
private void Page_Load(object sender, System.EventArgs e)
{
string file = MapPath("ff.zip");
FileInfo fi=new FileInfo (file);
long startPos = 0;
//所传输的文件长度
long fileTranLen = fi.Length;
//断点续传请求
if (Request.Headers["Range"] != null)
{
Response.StatusCode = 206;
startPos = long.Parse(Request.Headers["Range"].Replace("bytes=", "").Split('-')[0]);
fileTranLen -= startPos;
//Response.AddHeader("Accept-Ranges", "bytes");
//Content-Range: bytes [文件块的开始字节]-[传输文件的总大小]/[文件的总大小]
Response.AddHeader("Content-Range", string.Format("bytes {0}-{1}/{2}",startPos,fileTranLen,fi.Length));
}
Response.AddHeader("Content-Length", fileTranLen.ToString());
//基本的文件下载报文头
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + fi.Name);
//简单的流拷贝
System.IO.Stream fileStream = System.IO.File.OpenRead(file);
fileStream.Position = startPos;
byte[] buffer = new Byte[1024];
int count;
while ((count = fileStream.Read(buffer, 0, buffer.Length)) > 0)
{
Response.OutputStream.Write(buffer, 0, count);
}
fileStream.Close();
Response.End();
}
新闻热点
疑难解答
图片精选