多谢!代码如下:
System.Net.WebClient client = new  System.Net.WebClient();
client.Headers.Add ("user-agent", "WinampMPEG/2.7");
client.DownloadFile("http://localhost/m3uplay/tomp3.asp?SongID=148040","d:\\c.mp3");
这样得到的结果是一个5.01Mb的文件。
如果这样:
System.IO.Stream str = client.OpenRead("http://localhost/m3uplay/tomp3.asp?SongID=148040");
System.IO.FileStream fs = new FileStream("d:\\this.mp3",System.IO.FileMode.Create,System.IO.FileAccess.Write,System.IO.FileShare.Read);
byte[] buffer = new byte[1024];
int count;
int ps=0;
for(;;)
{
count=str.Read(buffer,0,1024);
ps+=count;
fs.Write(buffer,0,1024);
down=((float)ps)/(2048*1024);
fs.Flush();
if(count==0)break;
}
fs.Close();
str.Close();
这样得到的就是一个6M的文件,而且mp3播放起来很刺耳。
这是怎么回事?我要怎样能得到正确的结果呢?
btw:我最近总是觉得我在网络方面基础很差,可否推荐一些书来读?

解决方案 »

  1.   

    问题解决!我好笨啊
    fs.Write(buffer,0,count);这样才对。
    那这个帖子怎么办?分就分给荐书者了呀
      

  2.   

    来晚了,原来楼主自己解决了。没错啊count=str.Read(buffer,0,1024); 最后count不一定返回1024.楼主想看什么书啊??MSDN是最好的书啊!!
      

  3.   

    MSDN固然不错,可又没有讲网络系统一点的?我很多基本概念还不行呢。我想知道些底层的,不一定要.NET下的。
      

  4.   

    不一定要.Net下的,可以找一本书叫 Unix网络通讯的书
      

  5.   

    Professional .NET Network Programming
    C# Network Programming by Richard Blum