title: Server returned HTTP response code: 400 for URL HttpURLConnection.getInputStream for JSON POST data string
body: <p>I'm trying to establish a HttpUrlConnection to a URL for its POST method and trying to POST JSON data in the request header. In doing so i'm getting the response code 400 for the URL with the below payload:</p>
  
  <pre><code>    {
         "classResolver":"EXTERNAL_DATA",
         "id":12345,
         "idEntity":"MUM",
         "nameEntity":"XYZ",
         "olympicIdEntity":null,
         "sidCreator":"X123",
         "nameCreator":"XXX, Test",
         "createTime":"15-Jul-2015 17:56:36 GMT +05:30",
         "modifyTime":"15-Jul-2015 17:56:36 GMT +05:30",
         "valueDate":"15-Jul-2015",
         "submissionCutoff":"15-Jul-2015 17:56:36 GMT +05:30",
         "alertId":null,
         "repairFlagRequired":false,
         "callbackRequiredFlag":false,
         "statementRefDebit":null,
         "thirdPartyApproval":null,
         "thirdPartyApprDetails":null,
         "thirdPartyReln":null,
         "adviceRefDebit":null,
         "idTcc":null,
         "accName":null,
         "isAcctTPRest":false,
         "idEntityDebitAcc":null
      }
  </code></pre>
  
  <p>The total JSON payload has around 250 elements with almost the same data.</p>
  
  <p>The code is :</p>
  
  <pre><code>    URLConnection connection = null;
      connection = url.openConnection();
      connection.setRequestProperty("reqHeaderInfoJson", objectMapper.writeValueAsString(jsonObj));
      connection.setRequestProperty("Accept", mediaType);
      connection.setRequestProperty("Content-Type", mediaType);
      BufferedReader br=null;
      StringBuilder sb=null;
      InputStreamReader isr=null;
      try {
          isr=new InputStreamReader(connection.getInputStream(), "UTF-8");
          br = new BufferedReader(isr);
          sb = new StringBuilder();
          String line;
          while ((line = br.readLine()) != null) {
              sb.append(line);
              sb.append("\n");
          }
      } catch (Exception e) {
          logger.error("Number of header copied =&gt; headerCount=" + e.getStackTrace(),e);
          e.printStackTrace();
      }
  </code></pre>
  
  <p>The same works with any other JSON string. There is a definite problem with the JSON string that i'm passing. Can someone please suggest?</p>