title: Why HTTP POST returns code 400 (bad request)? HTTP POST Method
body: <p>Why server returns response code 400(bad request)? (doesn't work)</p>
  
  <pre><code>URL serverAddress = new URL(uri);
  HttpURLConnection connection = (HttpURLConnection) serverAddress.openConnection();
  connection.setDoOutput(true);
  connection.setDoInput(true);
  connection.setRequestProperty("Content-Type", contentType);
  connection.setRequestMethod("POST");
  int status = connection.getResponseCode(); // returns 400
  </code></pre>
  
  <p>For example this HTTP GET returns code 200: (works)</p>
  
  <pre><code>/** Creating Connection **/
   URL serverAddress = new URL(uri);
   HttpURLConnection connection = (HttpURLConnection) serverAddress.openConnection();
   connection.setRequestProperty("Content-Type", contentType);
   connection.setRequestMethod("GET");
   connection.setDoOutput(false);
   int status = connection.getResponseCode(); // returns 200
  </code></pre>