我使用自定义Java密钥库来完成此工作。这是我的代码:
CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));final SSLContext sslContext = SSLContexts.custom() .loadTrustMaterial(new File("my_keystore.jks"), keystorePassword.toCharArray(), new TrustSelfSignedStrategy()) .build();RestClient client = RestClient.builder(new HttpHost(host, port, scheme)).setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder .setDefaultCredentialsProvider(credentialsProvider) .setSSLContext(sslContext)).build();
为了创建密钥库,我通过Firefox下载了该域的证书,并使用:
keytool -import -v -trustcacerts -file my_domain.crt -keystore my_keystore.jks -keypass password -storepass password
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)