远程下载文件源码
2012-03-07 20:46
225 查看
/********** 小文件************/ Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=logo.gif"); System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://dotnet.aspx.cc/Images/logoSite.gif"); System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); byte[] bytes = new byte[response.ContentLength]; stream.Read(bytes, 0, Convert.ToInt32(response.ContentLength)); HttpContext.Current.Response.BinaryWrite(bytes); Response.Flush(); Response.Close(); /********** 大文件************/ HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.xljsf.com//admin/UploadFile/20076222121122.wma"); request.Timeout = 150000; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); Response.Clear(); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment;filename=20076222121122.wma"); int buffer = 1024; while (true) { byte[] bytes = new byte[buffer]; int alreadyRead = stream.Read(bytes, 0, buffer); if (alreadyRead == 0) break; if (alreadyRead == buffer) Response.BinaryWrite(bytes); else { byte[] lastBytes = new byte[alreadyRead]; for (int i = 0; i < alreadyRead; i++) lastBytes[i] = bytes[i]; Response.BinaryWrite(lastBytes); } } Response.End();
相关文章推荐
- (转)远程下载文件源码
- org.apache.tools.zip.*和org.apache.commons.httpclient.*实现远程文件打包下载,支持中文文件名(转)
- SpringMVC+BUI实现文件上传(附详解,源码下载)
- 第一页(服务端) :远程资源管理器 c#应用源代码,SERVICE + CLIENT 模式 可实现远程文件管理,下载功能
- eclipse从安装到配置一条龙记录(下载、安装、外观配色字体、文件编码、代码提示、JRE与源码路径&Javadoc、tomcat等的配置)
- [已解决]下载chromium源码 download_from_google_storage 无法下载文件
- Silverlight实用窍门系列:22.Silverlight使用WebService调用C++,Delphi编写的DLL文件【实例源码下载】
- python 从远程服务器下载日志文件的程序
- 文件下载 获取远程图片
- PHP实现远程下载文件到本地
- Asp.net大文件下载的实现思路及源码
- mars老师[Android开发视频教学].01_18 文件下载 源码
- Silverlight实用窍门系列:22.Silverlight使用WebService调用C++,Delphi编写的DLL文件【实例源码下载】
- 在远程计算机的CMD内下载FTP文件
- [Java]远程下载文件并读取实例方法
- java 通过SSH方式连接远程主机并上传和下载文件
- 发一个自定义标签源码 读取远程文件
- 远程登录及文件下载
- PHP下载远程文件到本地存储的方法
- Xutils源码文件下载方法的调用流程