ITeye博客

使用RestTemplate https时禁用证书检查

冷h锋 · 2018-11-29 11:17 · java · 编程语言 · Markdown


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().....
}


评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。