c#的 下载代码。 还可以扩展更多,看自己需求了。
/// <summary>
/// Get方式获取文件,支持超大文件
/// </summary>
/// <param name="url">GET路径</param>
/// <param name="data">get时带入body的数据</param>
/// <param name="buffsize">缓存尺寸,默认51200</param>
/// <param name="downloading">下载中事件</param>
/// <param name="beforGet">Get前</param>
/// <param name="beforReadStream">读取流前</param>
/// <param name="setFilePath">设置文件名</param>
/// <param name="afterGet">Get后,销毁response前</param>
/// <param name="onException">异常处理,返回true抛出异常,返回false不抛异常</param>
public async void GetToFile(string url, string data = "", int buffsize = 51200,
Action<DateTime, int, int> downloading = null,
Action<HttpRequestMessage> beforGet = null,
Action<HttpResponseMessage> beforReadStream = null,
Func<HttpResponseMessage, string> setFilePath = null,
Action<HttpResponseMessage> afterGet = null,
Func<Exception, bool> onException = null)
{
int intervals = 200; // downloading执行间隔