title: How to set an "Accept:" header on Spring RestTemplate request?
body: <p>I want to set the value of the <code>Accept:</code> in a request I am making using Spring's <code>RestTemplate</code>.</p>
  
  <p>Here is my Spring request handling code</p>
  
  <pre><code>@RequestMapping(
      value= "/uom_matrix_save_or_edit", 
      method = RequestMethod.POST,
      produces="application/json"
  )
  public @ResponseBody ModelMap uomMatrixSaveOrEdit(
      ModelMap model,
      @RequestParam("parentId") String parentId
  ){
      model.addAttribute("attributeValues",parentId);
      return model;
  }
  </code></pre>
  
  <p>and here is my Java REST client:</p>
  
  <pre><code>public void post(){
      MultiValueMap&lt;String, String&gt; params = new LinkedMultiValueMap&lt;String, String&gt;();
      params.add("parentId", "parentId");
      String result = rest.postForObject( url, params, String.class) ;
      System.out.println(result);
  }
  </code></pre>
  
  <p>This works for me; I get a JSON string from the server side.</p>
  
  <p>My question is: how can I specify the <code>Accept:</code> header (e.g. <code>application/json</code>,<code>application/xml</code>, ... ) and request method (e.g. <code>GET</code>,<code>POST</code>, ... ) when I use RestTemplate?</p>