2017-04-03 110 views

回答

0

我能够做到这一点,按照这个答案Receiving Multipart Response on client side (ClosableHttpResponse)中描述的内容。 我输入下面的库:

编译 'com.sun.mail:机器人邮箱:1.5.5'

所以我的代码现在是这样的:

Request request = new Request.Builder() 
     .url(url) 
     .addHeader("range", String.format("bytes=%s", TextUtils.join(", ", ranges))) 
     .build(); 
Response response = client.newCall(request).execute(); 
ByteArrayDataSource dataSource = new ByteArrayDataSource(response.body().byteStream(), response.body().contentType().toString()); 
MimeMultipart multipart = new MimeMultipart(dataSource); 
int count = multipart.getCount(); 
for (int i = 0; i < count; i++) { 
    BodyPart bodyPart = multipart.getBodyPart(i); 
    if (bodyPart.isMimeType("application/octet-stream")) { 
     processBinaryStream(bodyPart.getInputStream()); 
    } else { 
     // Or process different types of data 
     throw new Exception(String.format("Content type: %s cannot be parsed", bodyPart.getContentType())); 
    } 
} 

我仍然不满意,不得不导入整个邮件处理库,只是为了管理多部分响应。但是现在,问题一直存在,直到我找到或想出更好的解决方案。