Can HTTP multipart and chunking coexist?

前端 未结 1 1653
生来不讨喜
生来不讨喜 2020-12-29 14:10

I\'m using apache HttpClient to post several files to server. Here\'s the code:

    public static HttpResponse stringResponsePo         


        
相关标签:
1条回答
  • 2020-12-29 14:27

    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);
    
    0 讨论(0)
提交回复
热议问题