title: Server responds with "error : invalid image" to java http post request containing base64 image
body: <p>I am setting up a client written in Java which is supposed to send 2 base64 encoded images to a Server. The server responds with "error : invalid image"
  Apart from that, the Post request is supposedly formulated correctly.
  What am I missing here? </p>
  
  <p>This is the official documentation on the web API I am using:
  <a href="https://documenter.getpostman.com/view/5211511/RWaDYCUN#49003cb5-55d7-d363-bb64-d202fd8d9cd7" rel="nofollow noreferrer">https://documenter.getpostman.com/view/5211511/RWaDYCUN#49003cb5-55d7-d363-bb64-d202fd8d9cd7</a>
  I am specifically using the compare-faces endpoint.</p>
  
  <p>this.address contains the correct Url to the endpoint and the variables 
  image_camera and image_user contain instances of type BufferedImage.</p>
  
  <pre><code>public String compare() {
  
      String form1_64, form2_64;
  
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      Base64.Encoder encoder = Base64.getEncoder();
      try {
          String form1_net = "data:image/png;base64";
          String form2_net = "data:image/png;base64";
          // TODO invalid image file in FaceX response
          ImageIO.write(image_camera, "png", bos);
          form1_64 = encoder.encodeToString(bos.toByteArray());
          ImageIO.write(image_user, "png", bos);
          form2_64 = encoder.encodeToString(bos.toByteArray());
          form1_net += form1_64;
          form2_net += form2_64;
  
          String url = String.valueOf(this.address);
          HttpClient client = new DefaultHttpClient();
          HttpPost post = new HttpPost(url);
  
          List&lt;NameValuePair&gt; urlParams = new ArrayList&lt;&gt;();
          urlParams.add(new BasicNameValuePair("image_attr", form1_net));
          urlParams.add(new BasicNameValuePair("image_attr", form2_net));
  
          post.setHeader("user_id", "my-user-id");
          post.setHeader("user_key", "my-user-key");
  
          post.setEntity(new UrlEncodedFormEntity(urlParams));
  
          HttpResponse response = client.execute(post);
  
          BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
          StringBuffer result = new StringBuffer();
          String line;
          while ((line = rd.readLine()) != null) {
              result.append(line);
          }
  
          System.out.println(result.toString());
  
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      return null;
  }
  </code></pre>