---
title: "使用RestTemplate https时禁用证书检查"
author: "冷h锋"
date: "2018-11-29T11:17:50Z"
tags: []
categories: ["编程语言"]
slug: "resttemplate-https"
draft: false
lastmod: "2018-11-29T11:17:32Z"
id: 2434479
url: "https://zygself.iteye.com/blog/2434479"
---

```java

private RestTemplate restTemplate = new RestTemplate();
private static final HostnameVerifier PROMISCUOUS_VERIFIER = (s, sslSession ) -> true;
privite void test(){
        restTemplate.setRequestFactory( new SimpleClientHttpRequestFactory() {
            @Override
            protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
                if(connection instanceof HttpsURLConnection){
                    ((HttpsURLConnection) connection).setHostnameVerifier(PROMISCUOUS_VERIFIER);
                }
                super.prepareConnection(connection, httpMethod);
            }
        });
 //restTemplate.exchange().....
}


```