Windows Mobile上实现断点续传。
来源:互联网 发布:中国网络大电影趋势 编辑:程序博客网 时间:2024/06/06 01:16
最近看到有人在网上讲论WM上的下载工具,就提供个断点传的思路,供大家交流。
断点续传就是在上一次下载时断开的位置开始继续下载。在HTTP协议中,可以在请求报文头中加入Range段,来表示客户机希望从何处继续下载。
代码如下,在WM6环境下测试通过。
static void Main(string[] args)
{
string StrFileName="c://aa.zip"; //根据实际情况设置
string StrUrl="http://www.xxxx.cn/xxxxx.zip"; //根据实际情况设置
//打开上次下载的文件或新建文件
long lStartPos =0;
System.IO.FileStream fs;
if (System.IO.File.Exists(StrFileName))
{
fs= System.IO.File.OpenWrite(StrFileName);
lStartPos=fs.Length;
fs.Seek(lStartPos,System.IO.SeekOrigin.Current); //移动文件流中的当前指针
}
else
{
fs = new System.IO.FileStream(StrFileName,System.IO.FileMode.Create);
lStartPos =0;
}
//打开网络连接
try
{
System.Net.HttpWebRequest request =(System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(StrUrl);
if ( lStartPos>0)
request.AddRange((int)lStartPos); //设置Range值
//向服务器请求,获得服务器回应数据流
System.IO.Stream ns= request.GetResponse().GetResponseStream();
byte[] nbytes = new byte[512];
int nReadSize=0;
nReadSize=ns.Read(nbytes,0,512);
while( nReadSize >0)
{
fs.Write(nbytes,0,nReadSize);
nReadSize=ns.Read(nbytes,0,512);
}
fs.Close();
ns.Close();
Console.WriteLine("下载完成");
}
catch(Exception ex)
{
fs.Close();
Console.WriteLine("下载过程中出现错误:"+ex.ToString());
}
}
- Windows Mobile上实现断点续传。
- Windows Mobile上实现断点续传
- Windows Mobile上实现断点续传
- Windows Mobile上异形窗口的实现
- Windows Mobile上实现绚丽时钟效果
- Windows Mobile上实现可拖动的窗口
- Windows Mobile上实现图片任意角度旋转
- Windows Mobile上实现图片任意角度旋转
- Windows Mobile 天气预报实现
- windows mobile上发送短信
- windows mobile上打开收件箱
- Windows Mobile上使用钩子
- Windows Mobile上使用钩子
- Windows Mobile上的签名
- Windows Mobile上的菜单
- Windows Mobile上的签名
- Windows Mobile实现透明控件
- Windows Mobile Ping 命令实现
- 2009笔记本处理器最新排名
- 修改文件创建日期,访问日期和修改日期
- wait和waitpid函数的相关知识
- C#更改系统时间
- Java编程那些事儿70——抽象类和接口(三)
- Windows Mobile上实现断点续传。
- (转载)理智性挫折反应
- 暗算
- 如何写一份好的工程师简历
- 出来咋到
- linux tools
- MVC三层模型(struts+spring+hibernate)总结
- pool
- Swt编程中的HelloWorld