title: Setting "Host" header for Spring RestTemplate doesn't work
body: <p>I want to send an HTTP request using <a href="https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html" rel="noreferrer">Spring RestTemplate</a>, via the <a href="https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html#exchange-java.lang.String-org.springframework.http.HttpMethod-org.springframework.http.HttpEntity-java.lang.Class-java.lang.Object...-" rel="noreferrer">exchange</a> method.</p>
  
  <p>The third parameter is an instance of <code>HttpEntity</code>, which allows setting the headers/body of the request. I tried the following code snippet:</p>
  
  <pre class="lang-java prettyprint-override"><code>import org.springframework.http.*;
  import org.springframework.web.client.RestTemplate;
  
  public class Connector {
      public static void main(String[] args) {
  
          HttpHeaders headers = new HttpHeaders();
          headers.set("Host", "www.example.com");
          headers.set("User-Agent", "whatever");
  
  
          RestTemplate restTemplate = new RestTemplate();
  
          ResponseEntity&lt;String&gt; responseEntity = restTemplate.exchange(
                  "http://httpbin.org/headers", HttpMethod.GET,
                  new HttpEntity&lt;String&gt;(null, headers), String.class);
  
          System.out.println(responseEntity.getBody());
      }
  }
  </code></pre>
  
  <p>Notice that <a href="http://httpbin.org/headers" rel="noreferrer">http://httpbin.org/headers</a> is a simple HTTP Request &amp; Response Service, which (in this case) returns HTTP headers.</p>
  
  <p>The result of running the Java code is as follows:</p>
  
  <pre><code>{
    "headers": {
      "Accept": "text/plain, */*", 
      "Connection": "close", 
      "Host": "httpbin.org", 
      "User-Agent": "whatever"
    }
  }
  </code></pre>
  
  <p>As you can see, the <code>User-Agent</code> is set to what I wanted, but the <code>Host</code> is not.</p>
  
  <blockquote>
    <p>How can I set <code>Host</code> to the value I desire?</p>
  </blockquote>