HttpClient异常:javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

这个错误可以使用以下方法配置HttpClient来解决:

SSLContext sslContext = SSLContext.getDefault();
SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(
		    		sslContext,
		    		new String[]{"TLSv1.2"},
		    		null,
		    		NoopHostnameVerifier.INSTANCE);
Registry registry = RegistryBuilder.create()
					.register("https", sslConnectionFactory)
					.register("http", PlainConnectionSocketFactory.INSTANCE)
					.build();
HttpClientConnectionManager ccm = new BasicHttpClientConnectionManager(registry);
CloseableHttpClient httpClient = HttpClientBuilder.create()
			          .setSSLSocketFactory(sslConnectionFactory)
			          .setConnectionManager(ccm).build();

你可能感兴趣的:(HttpClient)