Hi all,
Just wanted to post a quick update. I have changed it as below and it works: NByteArrayEntity nbe = new NByteArrayEntity(data.toString().getBytes("UTF-8")); post.setEntity(nbe); post.addHeader(HttpHeaders.AUTHORIZATION,"Basic "+authStr); post.addHeader(HttpHeaders.CONTENT_TYPE,contentType); I stopped using MultipartEntityBuilder. It doesn't really give NIO support I think because it needs to be wrapped in a BufferedHttpEntity (this makes a copy of the content in memory). I am not sure if the above reasoning is correct or complete. Perhaps some one can clarify. Thanks again! ---- On Tue, 12 Jan 2016 04:49:28 -0800 Karthik R <rabbitco...@zoho.com>wrote ---- Hi, We want to use the HttpAsyncClient and NIO so that we can handle more requests with fewer threads. I am tasked with migrating from HttpComponents 3.1 to 4.5. The new API is very different from the earlier one and I need some help with the same. ByteArrayPartSource horA = new ByteArrayPartSource("data", data.toString().getBytes("UTF-8")); FilePart p1 = new FilePart("data", horA); StringPart encodingPart = new StringPart("encoded", "" + _encode); StringPart contentPart = new StringPart("content-type", "text/xml"); Part[] partes = { p1, encodingPart, contentPart }; post.setRequestEntity(new MultipartRequestEntity(partes, post.getParams())); I rewrote the whole thing above as: HttpEntity postEntity = MultipartEntityBuilder.create() .addTextBody("content-type", contentType) .addTextBody("encoded", ""+true) .addBinaryBody("data", data.toString().getBytes("UTF-8")) .build(); post.setEntity(postEntity); This results in UnsupportedOperationException:Multipart form entity does not implement #getContent() I read similar posts on this list but didn't understand what I should do. I don't want to write copy content into memory/buffer. What is the right way to write this using 4.5 and HttpAsyncClient? Any pointers will be really appreciated. Thanks!