2017-04-03 1 views

Antwort

0

Ich konnte es tun, indem ich folge, was in dieser Antwort beschrieben wird Receiving Multipart Response on client side (ClosableHttpResponse). Ich importierte die unter Bibliothek:

Kompilierung 'com.sun.mail: android-mail: 1.5.5'

meinen Code So ist nun wie folgt aus:

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())); 
    } 
} 

Ich bin immer noch nicht zufrieden, muss diese ganze Mail-Handling-Bibliothek importieren, nur um Multipart-Antwort zu verwalten. Aber jetzt ist das Problem behoben, bis ich eine bessere Lösung finde oder finde.

Verwandte Themen