C#上的协议违规,试图连接到SHOUTCast

时间:2015-01-23 19:30:38

标签: c# webrequest shoutcast webresponse

我在Visual C#上制作一个程序,试图连接到Shoutcast收音机并下载音频。但是,我在GetResponse()函数上遇到协议违规错误。 我听说Shoutcast不是常见的HTTP协议,我没有找到任何与特殊连接相关的数据。 我的代码中有这样的东西:

private void downloadPart()
    {
        System.Net.WebRequest conn;
        System.Net.WebResponse connResp;
        System.IO.Stream readStream = null;
        System.IO.FileStream writeStream;
        int bufferSize = 8192;
        try
        {
            conn = System.Net.WebRequest.Create(this.caminhoURL);
            connResp = conn.GetResponse();
            readStream = connResp.GetResponseStream();
            writeStream = new System.IO.FileStream(@"C:\", System.IO.FileMode.Create, System.IO.FileAccess.Write);
            int length;
            byte[] buffer = new Byte[bufferSize];
            do
            {
                length = readStream.Read(buffer, 0, bufferSize);
                writeStream.Write(buffer, 0, length);
                System.Diagnostics.Debug.WriteLine("Working");
                readStream.Flush();
            } while (length > 0);
        }
        catch (Exception e) 
        {
            System.Diagnostics.Debug.WriteLine(e.StackTrace);
        }
        finally
        {
            if (fluxoLeitura != null)
            {
                fluxoLeitura.Close();
                System.Diagnostics.Debug.WriteLine("Done");
            }
        }
    }

我已经测试过这个功能来下载一个简单的文件,但它确实有效。 我知道流是连续的,所以我不能将它全部下载到一个文件中,我只需要知道如何配置连接。 我该怎么做?

0 个答案:

没有答案