title: Ignore SSL certificate validation when using Spring RestTemplate
body: <p>I am using Spring RestTemplate to make HTTPS requests, and I want to ignore SSL certificate</p>
  
  <p>Here is my code to create the restTemplate request:</p>
  
  <pre><code>TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String 
  authType) -&gt; true;
  SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
  .loadTrustMaterial(null, acceptingTrustStrategy)
  .build();
  SSLConnectionSocketFactory csf = new 
  SSLConnectionSocketFactory(sslContext);
  loseableHttpClient httpClient = HttpClients.custom()
  .setSSLSocketFactory(csf)
  .build();
  HttpComponentsClientHttpRequestFactory requestFactory =
  new HttpComponentsClientHttpRequestFactory();
  requestFactory.setHttpClient(httpClient);
  RestTemplate restTemplate = new RestTemplate(requestFactory);
  ...
  response = restTemplate.exchange("https://192.168.1.2:/foo/bar", 
  HttpMethod.POST, entity,String.class);
  </code></pre>
  
  <p>This request works when I use the server hostname, 
  But I get the following Exception when I use the server IP address:</p>
  
  <pre><code>Exception in thread "main" 
  org.springframework.web.client.ResourceAccessException: I/O error on POST 
  request for "https://192.168.1.2/foo/bar": Certificate for 
  &lt;192.168.1.2&gt; doesn't match any of the subject alternative names: []; 
  nested exception is javax.net.ssl.SSLPeerUnverifiedException: Certificate 
  for &lt;192.168.1.2&gt; doesn't match any of the subject alternative names: []
  
  Caused by: javax.net.ssl.SSLPeerUnverifiedException: Certificate for 
  &lt;192.168.1.2&gt; doesn't match any of the subject alternative names: []
  </code></pre>