私は、本質的に1つのサーバーから別のサーバーにファイルを "プロキシ"している次のコードを持っています。それはIEで完全に動作しますが、FirefoxはContent-Type
ヘッダーを無視して、常にファイル(MP3)をtext/html
として送信します。FirefoxはResponse.ContentTypeを無視します
これは大きな問題ではありませんが、すべてのブラウザで正しく機能するようにしたいので、誰でも手伝っていただけますか?また、これを達成するためのより良い/より効率的な方法がある場合は、投稿してください!
FileInfo audioFileInfo = new FileInfo(audioFile);
HttpWebRequest downloadRequest = (HttpWebRequest) WebRequest.Create(audioFile);
byte[] fileBytes;
using (HttpWebResponse remoteResponse = (HttpWebResponse) downloadRequest.GetResponse())
{
using (BufferedStream responseStream = new BufferedStream(remoteResponse.GetResponseStream()))
{
fileBytes = new byte[remoteResponse.ContentLength];
responseStream.Read(fileBytes, 0, fileBytes.Length);
Response.ClearContent();
// firefox seems to ignore this...
Response.ContentType = Utilities.GetContentType(audioFileInfo);
// ... and this
//Response.ContentType = remoteResponse.ContentType;
Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", audioFileInfo.Name));
Response.AddHeader("Content-Length", remoteResponse.ContentLength.ToString());
Response.BinaryWrite(fileBytes);
Response.End();
}
}
"IEでは完全に機能します。" IEはコンテンツの最初のxバイトからコンテンツタイプを推測しようとします。おそらく間違ったタイプ(または何もありません)を送信している可能性があります。 –
remoteResponse.ContentTypeとUtilities.GetContentType(audioFileInfo)の両方が "audio/mpeg"を返します。これはMP3に適しています。 –