【发布时间】:2011-09-01 08:09:30
【问题描述】:
我正在使用 Apache HttpClient 连接到服务器以下载 .wav 文件。我在我的程序中使用 HTTP POST 方法。
服务器正确响应以下标头和正文:
> HTTP/1.1 200 OK\r\n Content-Disposition: attachment;
> filename=saveme1.mp3\r\n Content-Length: 6264\r\n
> Content-Transfer-Encoding: binary\r\n Content-Type: audio/mp3\r\n
现在如何从 HTTP 响应中提取 saveme1.mp3 文件?我正在使用以下代码:
ResponseHandler<String> responseHandler = new BasicResponseHandler();
byte[] data = httpclient.execute(httppost, responseHandler).getBytes();
但是,当我将数据写入文件时,我得到了垃圾。
FileOutputStream fileoutputstream = new FileOutputStream(outputFile);
for (int i = 0; i < data.length; i++)
fileoutputstream.write(data[i]);
【问题讨论】:
标签: mp3 httpclient