title: Java MultiPart post
body: <p>I am trying to create a multipart post to a URL with the following body:</p>
  
  <pre><code>Content-Disposition: form-data; name="json"
  Content-Type: "application/json; charset=UTF-8"
  
  {"input1":"data1","input2":"data2","input3":"data3"}
  
  --APIMultipartPost
  Content-Disposition: form-data; name="filePath"; filename="myFile.dat"
  Content-Length: 381645
  Content-Type: text/plain
  Content-Transfer-Encoding: binary
  
  &lt;!-- SNIP --&gt;
  &lt;!-- The OWL file was included here in plain text (without the SNIPs) --&gt;
  &lt;!-- SNIP --&gt;
  </code></pre>
  
  <p>I tried using MultipartEntityBuilder to create the multipart post, but probably I do something wrong with the parameters.
  Can someone help me with the java code for this post?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>CloseableHttpClient httpClient = HttpClients.createDefault();
  HttpPost uploadFile = new HttpPost(URL);
  
  MultipartEntityBuilder builder = MultipartEntityBuilder.create();
  builder.addTextBody("input1", "data1");
  builder.addTextBody("input2", "data2");
  builder.addTextBody("input3", "data3");
  
  builder.addBinaryBody("file", new File("C:/myFile.dat"), ContentType.APPLICATION_OCTET_STREAM, "myFile.dat");
  HttpEntity multipart = builder.build();
  uploadFile.setEntity(multipart);
  HttpResponse response = httpClient.execute(uploadFile);
  </code></pre>
  
  <p>and the error I get:</p>
  
  <pre><code>HttpResponseProxy{HTTP/1.1 422 Unprocessable Entity [Server: nginx/1.6.0, Date: Wed, 28 Jan 2015 19:29:42 GMT, Content-Type: application/json;charset=utf-8, Content-Length: 89, Connection: keep-alive, Status: 422 Unprocessable Entity, X-Rack-Cache: invalidate, pass, X-Content-Type-Options: nosniff] ResponseEntityProxy{[Content-Type: application/json;charset=utf-8,Content-Length: 89,Chunked: false]}}
  </code></pre>
  
  <p>Thank you!</p>