.Net实现文件下载Demo
来源:互联网 发布:网络项目70000元 编辑:程序博客网 时间:2024/05/21 23:59
using System;using System.IO;using System.Net;namespace downlown{ public class DownLoadDemo { /// <summary> /// request访问方式,默认GET /// </summary> public string Method { get; set; } /// <summary> /// request过期时间(不能为0) /// </summary> public int Timeout { get; set; } /// <summary> /// 资源url(必需) /// </summary> public string url { get; set; } /// <summary> /// 下载到本地的路径(必需) /// </summary> public string path { get; set; } public DownLoadDemo() { this.Method = "GET"; this.Timeout = 12000; } public DownLoadDemo(string url, string path) : this() { this.url = url; this.path = path; } protected HttpWebRequest CreateRequest() { if (url == null) { throw new Exception("url为非法输入!"); } HttpWebRequest request = WebRequest.Create(this.url) as HttpWebRequest; request.Method = this.Method; request.Timeout = this.Timeout; return request; } public void DownLoad() { Stream stream = null; FileStream fs = null; HttpWebRequest request = CreateRequest(); HttpWebResponse response = request.GetResponse() as HttpWebResponse; try { int length = 2048; byte[] buffer = new byte[length]; stream = response.GetResponseStream(); fs = new FileStream(path, FileMode.Create, FileAccess.Write); while (stream.Read(buffer, 0, length) > 0) { fs.Write(buffer, 0, length); } } catch (Exception ex) { // do something } finally { if (stream != null) { stream.Close(); } if (fs != null) { fs.Close(); } } } }}
1 0
- .Net实现文件下载Demo
- servlet实现文件下载demo
- .net 实现文件下载
- ASP.NET实现文件下载
- ASP.NET实现文件下载
- ASP.NET实现文件下载
- asp.net实现文件下载
- ASP.NET实现文件下载
- asp.net 实现文件下载
- ASP.net实现文件下载
- ASP.NET实现文件下载
- .net remoting demo 下载
- jsp下载文件demo
- 下载文件demo
- python下载文件DEMO
- python下载文件demo
- 多线程下载文件!Demo
- asp.net文件下载,实现隐藏文件下载地址
- 对nodejs express 框架的简单封装实现快速开发
- 月try如同一条yui
- 系统时间的差别
- libaio linux 原生异步io
- draw的this.parent在前面才行
- .Net实现文件下载Demo
- Could not clean server of obsolete files: 前言中不允许有内容。前言中不允许有
- NSRange 使用...
- where does root (/) mount point exist — linux
- svn服务器地址变换以后,mac下的处理方法
- 把选中的商品信息传到另外一个页面
- 博客搬家了,搬家了
- Error: "select_city_zzdw" is not translated in "zh" (Chinese) [MissingTranslation]
- layer-list(图层叠加)