httpwebrequest下载文件的例子 能不能给个下载的小例子,比如这个http://www.hongchuang.com/国家.mp3,,,在网上找了很多时间,没找到好的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 WebClient wc = new WebClient();wc.DownloadFile("http://www.hongchuang.com/国家.mp3","c:\\国家.mp3"); 一段显示下载进度条的下载文件代码http://dotnet.aspx.cc/article/7107b5f4-ff3a-4890-8414-5eb17d50eabf/read.aspx HttpWebRequest实现的,国家.mp3好大,我等了5分钟才下载完如果没用多线程的话,下载完之前界面会失去响应 WebRequest request = HttpWebRequest.Create("http://www.hongchuang.com/国家.mp3"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); System.IO.Stream stream = response.GetResponseStream(); byte[] data = new byte[1024]; System.IO.FileStream fs = new System.IO.FileStream(@"d:\国家.mp3",System.IO.FileMode.Create); int sum = 0; int count; while (sum < response.ContentLength) { count=stream.Read(data, 0, data.Length); fs.Write(data, 0, count); sum += count; } fs.Close(); stream.Close(); 原来“孟子”在这个板块,还记得英雄会时你的发言,,呵呵,,感谢4楼的分享,以前一直没有接触过这个,ms c#的书上也很少有这个HttpWebRequest,,请问这个资料在哪找?msdn上也不是那么详细 WebRequest request = HttpWebRequest.Create("http://www.hongchuang.com/国家.mp3"); //创建请求 HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //发出请求并获得回复 System.IO.Stream stream = response.GetResponseStream(); //得到与服务器的流 byte[] data = new byte[1024]; System.IO.FileStream fs = new System.IO.FileStream(@"d:\国家.mp3",System.IO.FileMode.Create); int sum = 0; //统计已读取的文件大小 int count; while (sum < response.ContentLength) //循环读取直到达到文件大小 { count=stream.Read(data, 0, data.Length); fs.Write(data, 0, count); //写入文件 sum += count; } fs.Close(); stream.Close(); 这里,为什么不能用var 请教WndProc的问题 owc问题!引用owc的页面在安装office2000的机器上可以打开,但在安装office2003的页面打不开!为什么? 怎么在C#实现资源管理器? 关于dataGrid ,请问怎么知道 dataGrid控件的值,是否被编辑过? 监视sql2000 的操作 如何在click事件里知道是按了哪个mouse button呢? 如何向datagrid传递一个消息? 新手:datagrid的用法??? 高手请进!! 关于进度条一次显示至满的问题 bindingsource的重新绑定问题
wc.DownloadFile("http://www.hongchuang.com/国家.mp3","c:\\国家.mp3");
WebRequest request = HttpWebRequest.Create("http://www.hongchuang.com/国家.mp3");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.IO.Stream stream = response.GetResponseStream();
byte[] data = new byte[1024];
System.IO.FileStream fs = new System.IO.FileStream(@"d:\国家.mp3",System.IO.FileMode.Create);
int sum = 0;
int count;
while (sum < response.ContentLength)
{
count=stream.Read(data, 0, data.Length);
fs.Write(data, 0, count);
sum += count;
}
fs.Close();
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //发出请求并获得回复
System.IO.Stream stream = response.GetResponseStream(); //得到与服务器的流
byte[] data = new byte[1024];
System.IO.FileStream fs = new System.IO.FileStream(@"d:\国家.mp3",System.IO.FileMode.Create);
int sum = 0; //统计已读取的文件大小
int count;
while (sum < response.ContentLength) //循环读取直到达到文件大小
{
count=stream.Read(data, 0, data.Length);
fs.Write(data, 0, count); //写入文件
sum += count;
}
fs.Close();
stream.Close();