我使用 range hader,但没有创建正确的文件。
如果我发送 Range bytes=0-8999
文件重 9000 字节并且正确工作。
如果我发送 Range bytes=0-8999,9000-9999
文件重 10213 字节并且不正确工作。
文件类型 mp3。
有什么问题吗?
HttpGet first = new HttpGet("http://cs4832.vkontakte.ru/u50184979/audio/ef64581d913c.mp3");
first.addHeader("Accept-Ranges", "bytes");
first.addHeader("Range", "bytes=0-8999,9000-9999");
//first.addHeader("Accept-Ranges", "bytes");
HttpResponse response = httpclient.execute(first, localContext);
InputStream instream = response.getEntity().getContent();
File f = new File("outFile1.mp3");
OutputStream out = new FileOutputStream(f);
byte buf[] = new byte[1024];
int len;
while ((len = instream.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
instream.close();
最佳答案
When an HTTP message includes the content of multiple ranges (for example, a response to a request for multiple non-overlapping ranges), these are transmitted as a multipart message. The multipart media type used for this purpose is "multipart/byteranges" as defined in Appendix 19.2. See Appendix 19.6.3 for a compatibility issue.
关于java - 如何使用范围 header 组装文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5981564/