直接抄网上的示例,发现会证书认证失败:
unable to find valid certification path to requested target
需要先配置SSLcontext和SSLSocketFactory。直接上代码
try {
sslContext = SSLContext.getInstance("TLS");
} catch (NoSuchAlgorithmException
e) {
e.printStackTrace();
}
TrustManager tm = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}