title: How to send POST request through RestTemplate with custom parameter in header
body: <p>I need to send post request with custom parameter("data" containing path) and set content type as text/plain. I looked through a ton of similar question but none of the solutions posted helped.</p>
  
  <p>The method should list files from this directory.</p>
  
  <p>my code is     </p>
  
  <pre><code>    public List&lt;FileWrapper&gt; getFileList() {
  
      MultiValueMap&lt;String, String&gt; map = new LinkedMultiValueMap&lt;String, String&gt;();
      map.add("data", "/public/");
  
      HttpHeaders headers = new HttpHeaders();
      headers.setContentType(MediaType.TEXT_PLAIN);
  
      HttpEntity&lt;MultiValueMap&lt;String, String&gt;&gt; request = new HttpEntity&lt;MultiValueMap&lt;String, String&gt;&gt;(
              map, headers);
      String url = "http://192.168.1.51:8080/pi/FilesServlet";
      restTemplate.getMessageConverters().add(new FormHttpMessageConverter());
      restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
      String response = restTemplate
              .postForObject(url, request, String.class);
      List&lt;FileWrapper&gt; list = new ArrayList&lt;&gt;();
      for (String part : response.split("\\|")) {
          System.out.println("part " + part);
          list.add(new FileWrapper(part));
      }
      return list;
  }
  </code></pre>
  
  <p>Here's working code equivalent written in javascript: </p>
  
  <pre><code>function getFileList(direction){
  $("div.file-list").html("&lt;center&gt;&lt;progress&gt;&lt;/progress&gt;&lt;/center&gt;");
  $.ajax({
    url: "http://192.168.1.51:8080/pi/FilesServlet",
    type: "POST",
    data: direction ,
    contentType: "text/plain"
  })
  </code></pre>
  
  <p>The parameter is not added as the request returns empty string meaning the path is not valid. The expected response is <code>file_name*file_size|file_name*file_size ...</code></p>
  
  <p>Thanks in advance.</p>