title: Sending POST http request in java
body: <p>What is the best way to translate the next curl request to a single Java request code?</p>
  
  <pre><code>$ curl -i
    -H 'Content-Type: multipart/form-data' \
    -H "Accept: application/json" \
    -F "user[photo]=@test.jpg" \
    -F "user[first_name]=Test" \
    -F "user[password]=password" \
    -F "user[email]=email@test.com" \
    -F "user[last_name]=Testing" \
    -X POST http://someURL.com:3000/api/user?client_id=zyBCF8N6yiJq8k
  </code></pre>
  
  <p>*I've already tried the next:</p>
  
  <pre><code>    HttpPost postRequest = new HttpPost(AP("users", null));
      FileBody bin = new FileBody(new File(IMAGE_DIR + "/" + "nisbet-profile.jpg"));
      log.info("exporting file in path " + bin.getFile().getPath());
      MultipartEntity entity = new MultipartEntity();
      entity.addPart("photo", bin);
      entity.addPart("first_name", new StringBody("test"));
      entity.addPart("last_name", new StringBody("test"));
      entity.addPart("email", new StringBody("testemail23@gmail.com"));
      entity.addPart("password", new StringBody("123456"));
  
      RestExporter picExporter = new RestExporter();
      postRequest.setEntity(entity);
      HttpResponse response = picExporter.request(postRequest);
  
  
  
      but I get: HTTP/1.1 422 Unprocessable Entity
  
      Any idea what I'm doing wrong?
  </code></pre>