Can HTTP multipart and chunking coexist?

ぐ巨炮叔叔 提交于 2019-11-30 05:21:53

Got a solution for my second question, the trick is to write MultipartEntity to a ByteArrayOutputStream, create a ByteArrayEntity from ByteArrayOutputStream and enable chunking on that. Here's the the code:

    ByteArrayOutputStream bArrOS = new ByteArrayOutputStream();
    // reqEntity is the MultipartEntity instance
    reqEntity.writeTo(bArrOS);
    bArrOS.flush();
    ByteArrayEntity bArrEntity = new ByteArrayEntity(bArrOS.toByteArray());
    bArrOS.close();

    bArrEntity.setChunked(true);
    bArrEntity.setContentEncoding(reqEntity.getContentEncoding());
    bArrEntity.setContentType(reqEntity.getContentType());

    // Set ByteArrayEntity to HttpPost
    post.setEntity(bArrEntity);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!