title: SPRING BOOT: RestTemplate postForObject 400 bad request
body: <p>I keep receiving a 400 BAD request when sending a POST request using RestTemplate. Here's my code:</p>
  
  <pre><code>    MultiValueMap&lt;String, Object&gt; requestBody = new LinkedMultiValueMap&lt;String, Object&gt;();
      requestBody.add("message_id", "msgid");
      requestBody.add("message", "qwerty");
      requestBody.add("client_id", "111");
      requestBody.add("secret_key", "222");
  
      MultiValueMap&lt;String, String&gt; headers = new LinkedMultiValueMap&lt;String, String&gt;();
      headers.add("Accept", "application/json");
      headers.add("Content-Type", "application/json");
  
      HttpEntity&lt;MultiValueMap&lt;String, String&gt;&gt; httpEntity = new HttpEntity&lt;MultiValueMap&lt;String, String&gt;&gt;(requestBody, headers);
  
      RestTemplate restTemplate = new RestTemplate();
      String response = restTemplate.postForObject("https://abc.com/api/request", httpEntity, String.class);
      JSONParser parser = new JSONParser();
      try {
          JSONObject jsonObject = (JSONObject) parser.parse(response);
          System.out.println(jsonObject.get("status"));
      } catch (ParseException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>What I am trying to achive is to convert the ff. php code to spring:</p>
  
  <pre><code>&lt;?php
  $arr_post_body = array(
    "message_id" =&gt; "qwerty",
    "message" =&gt; "Welcome to My life!",
    "client_id" =&gt; "111",
    "secret_key" =&gt; "222"
  );
  
  $query_string = "";
  foreach($arr_post_body as $key =&gt; $frow)
  {
      $query_string .= '&amp;'.$key.'='.$frow;
  }
  
  $URL = "https://abc.com/api/request";
  $curl_handler = curl_init();
  curl_setopt($curl_handler, CURLOPT_URL, $URL);
  curl_setopt($curl_handler, CURLOPT_POST, count($arr_post_body));
  curl_setopt($curl_handler, CURLOPT_POSTFIELDS, $query_string);
  curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, TRUE);
  $response = curl_exec($curl_handler);
  curl_close($curl_handler);
  exit(0);
  
  ?&gt;
  </code></pre>
  
  <p>Is there something wrong? Please take note that I am POSTing to an external link(API) and it is HTTPS.</p>