title: calling third party api using httpurlconnection
body: <p>I am trying to call third party api from my controller to get token (POST request) but getting 400, we are using java.net.HttpURLConnection</p>
  
  <p>I tried adding different type of header used but no luck, I also tried with RESTTemplate but same issue. same is working in swagger UI provided by third party, I searched over internet and tried different solution but no luck.</p>
  
  <pre><code>public String getToken(String requestJsonString) {
          String responseJSONString = "";
          URL constructedURL = null;
          HttpURLConnection httpConnection = null;
          String url = null;
  
          url = "any url"; //dummy
          try {
              constructedURL = new URL(url);
              httpConnection = (HttpURLConnection) constructedURL.openConnection();
              httpConnection.setDoOutput(Boolean.TRUE);
              httpConnection.setRequestMethod(RaterConstants.POST);
              httpConnection.setRequestProperty("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
              httpConnection.setRequestProperty("accept", RaterConstants.APPLICATION_JSON);
  
              OutputStream os = httpConnection.getOutputStream();
              os.write(requestJsonString.getBytes());
              os.flush();
  
              InputStream inputStream;
              if (httpConnection.getResponseCode() &gt;= 400) {
                  inputStream = httpConnection.getErrorStream();
              } else {
                  inputStream = httpConnection.getInputStream();
              }
  
              BufferedReader br = new BufferedReader(new InputStreamReader((inputStream)));
              String output;
              while ((output = br.readLine()) != null) {
                  responseJSONString = output;
              }
              httpConnection.disconnect();
          }catch (IOException e) {
              logger.error("Error occurred in AccessTokenData : getToken : " + e.getCause());
          }
          return responseJSONString;
      }
  </code></pre>
  
  <p>Request Header from swagger UI - got it from dev tool</p>
  
  <pre><code>POST /Test HTTP/1.1
  Host: host
  Connection: keep-alive
  Content-Length: 87
  accept: application/json
  User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
  Sec-Fetch-Mode: cors
  Content-Type: application/x-www-form-urlencoded
  Origin: url
  Sec-Fetch-Site: same-origin
  Referer: url
  Accept-Encoding: gzip, deflate, br
  Accept-Language: en-US,en;q=0.9
  Cookie: PF=Ycbz2Gt6Bwyeguyegyue
  </code></pre>
  
  <p>requestJsonString is correct as I tried in swagger, It might be request headers missing, please help with your expertise. I expect to return 200.</p>