I tinkered a bit and did two things to get the code working.
- no longer use addPart(...)
- no longer set Content-Type header
Here's the revised snippet that's working in case anyone is interested.
HttpEntity entity = MultipartEntityBuilder
.create()
.addTextBody("field1","val1")
.addTextBody("field2","val2")
.addBinaryBody("file", new File("somefile.zip"),ContentType.create("application/zip"),"somefile.zip")
.build();
HttpPost post = new HttpPost("https://www.some.domain");
post.setEntity(entity);
I also set HttpComponents to debug mode.
-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog -Dorg.apache.commons.logging.simplelog.showdatetime=true -Dorg.apache.commons.logging.simplelog.log.org.apache.http=DEBUG
It turns out that each part now has a boundary. Even better yet, the Content-Type and boundary are autogenerated.
Content-Type: multipart/form-data; boundary=5ejxpaJqXwk2n_3IVZagQ1U0_J_X9MdGvst9n2Tc