使用RestTemplate https时禁用证书检查

阅读更多
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().....
}

你可能感兴趣的:(java,https,ssl)