如何使用范围标题汇编文件? [英] How to assemble the file using the range header?
问题描述
我使用范围黑客,但没有创建正确的文件。
I use range hader, but not create correct file.
如果我发送范围字节= 0-8999
文件重9000字节,正确工作。
如果我发送范围字节= 0-8999,9000-9999
文件重10213字节,不正确工作。
if I send Range bytes=0-8999
file weighs 9000 bytes and correct work.
if I send Range bytes=0-8999,9000-9999
file weighs 10213 bytes and NOT correct work.
文件类型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();
推荐答案
参见 RFC 2616,第14.16节:
当HTTP消息包含多个范围的内容时(例如,对多个非重叠范围的请求的响应),这些内容将作为多部分消息进行传输。用于此目的的多部分媒体类型是附录19.2中定义的多部分/字节范围。有关兼容性问题,请参阅附录19.6.3。
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.
这篇关于如何使用范围标题汇编文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!