能不能给个下载的小例子,比如这个http://www.hongchuang.com/国家.mp3,,,在网上找了很多时间,没找到好的

解决方案 »

  1.   

    WebClient wc = new WebClient();
    wc.DownloadFile("http://www.hongchuang.com/国家.mp3","c:\\国家.mp3");
      

  2.   

    一段显示下载进度条的下载文件代码http://dotnet.aspx.cc/article/7107b5f4-ff3a-4890-8414-5eb17d50eabf/read.aspx
      

  3.   

     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.   

    原来“孟子”在这个板块,还记得英雄会时你的发言,,呵呵,,感谢4楼的分享,以前一直没有接触过这个,ms  c#的书上也很少有这个HttpWebRequest,,请问这个资料在哪找?msdn上也不是那么详细
      

  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();