title: Passing HttpServletRequest to another API controller
body: <p>I have a controller that receives <code>HttpServletRequest</code> with body <code>form-data</code> with some <code>key-value</code></p>
  
  <p>I want to pass this <code>HttpServletRequest</code> to another API. That another API controller receives <code>HttpServletRequest</code></p>
  
  <p>So far, I've tried this in my service class.</p>
  
  <pre><code>public void saveApi(HttpServletRequest request) throws Exception {
      System.out.println(request.getCode());
      RestTemplate restTemplate = new RestTemplate();         
      HttpServletRequest result = restTemplate.postForObject( "http:localhost:8080/save", request, HttpServletRequest .class);
  }
  </code></pre>
  
  <p>The result is the other API <code>java.lang.NullPointerException: null</code>, other API didn't receive my post. </p>
  
  <p>How to do that? Is it possible? </p>
  
  <p>Another service, for example: <code>GET</code> method, I use the <code>RestTemplate</code> to call to another API with some parameter, it succeeds.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>the answer is:</p>
  
  <pre><code>HttpHeaders httpHeaders = new HttpHeaders();
  httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
  
  MultiValueMap&lt;String, Object&gt; form = new LinkedMultiValueMap&lt;&gt;();
  form.add("name", request.getParameter("name"));
  form.add("blabla", request.getParameter("blabla"));
  form.add("blabla", request.getParameter("blabla"));
  
  HttpEntity&lt;MultiValueMap&lt;String, Object&gt;&gt; requestEntity = new HttpEntity&lt;&gt;(form, httpHeaders);
  restTemplate.postForEntity("http:localhost:8080/save", requestEntity, String.class);
  </code></pre>