C#實現支持斷點續傳多線程下載客戶端工具類
2024-09-07 17:05:32
供稿:網友
代碼如下:
/* .Net/C#: 實現支持斷點續傳多線程下載的 Http Web 客戶端工具類 (C# DIY HttpWebClient)
* Reflector 了一下 System.Net.WebClient ,改寫或增加了若干:
* DownLoad、Upload 相關方法!
* DownLoad 相關改動較大!
* 增加了 DataReceive、ExceptionOccurrs 事件!
* 了解服務器端與客戶端交互的 HTTP 協議參閱:
* 使文件下載的自定義連接支持 FlashGet 的斷點續傳多線程鏈接下載! JSP/Servlet 實現!
* http://blog.csdn.net/playyuer/archive/2004/08/02/58430.aspx
* 使文件下載的自定義連接支持 FlashGet 的斷點續傳多線程鏈接下載! C#/ASP.Net 實現!
* http://blog.csdn.net/playyuer/archive/2004/08/02/58281.aspx
*/
//2005-03-14 修訂:
/* .Net/C#: 實現支持斷點續傳多線程下載的工具類
* Reflector 了一下 System.Net.WebClient ,改寫或增加了若干:
* DownLoad、Upload 相關方法!
* 增加了 DataReceive、ExceptionOccurrs 事件
*/
namespace Microshaoft.Utils
{
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Security;
using System.Threading;
using System.Collections.Specialized;
/// <summary>
/// 記錄下載的字節位置
/// </summary>
public class DownLoadState
{
private string _FileName;
private string _AttachmentName;
private int _Position;
private string _RequestURL;
private string _ResponseURL;
private int _Length;
private byte[] _Data;
public string FileName
{
get
{
return _FileName;
}
}
public int Position
{
get
{
return _Position;
}
}
public int Length
{
get
{
return _Length;
}
}
public string AttachmentName
{
get
{
return _AttachmentName;
}
}
public string RequestURL
{
get
{
return _RequestURL;
}
}
public string ResponseURL
{
get
{
return _ResponseURL;
}
}
public byte[] Data
{
get
{
return _Data;
}
}
internal DownLoadState(string RequestURL, string ResponseURL, string FileName, string AttachmentName, int Position, int Length, byte[] Data)
{
this._FileName = FileName;
this._RequestURL = RequestURL;
this._ResponseURL = ResponseURL;
this._AttachmentName = AttachmentName;
this._Position = Position;
this._Data = Data;
this._Length = Length;
}
internal DownLoadState(string RequestURL, string ResponseURL, string FileName, string AttachmentName, int Position, int Length, ThreadCallbackHandler tch)
{
this._RequestURL = RequestURL;
this._ResponseURL = ResponseURL;
this._FileName = FileName;
this._AttachmentName = AttachmentName;
this._Position = Position;
this._Length = Length;
this._ThreadCallback = tch;
}
internal DownLoadState(string RequestURL, string ResponseURL, string FileName, string AttachmentName, int Position, int Length)
{