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");
}
}
}
この機能をテストして単純なファイルをダウンロードしましたが、うまくいきました。ストリームが連続していることはわかっているので、すべてを 1 つのファイルにダウンロードすることはできません。接続の構成方法を知る必要があるだけです。どうすればいいですか?