2017-04-03 3 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())); 
    } 
} 

私はまだこのメール処理ライブラリ全体をインポートすることなく、マルチパートレスポンスを管理するだけで満足していません。しかし、今のところ、問題は私が見つけるか解決策が見つかるまで修正されています。