Java HttpsURLConnection和TLS 1.2

Java HttpsURLConnection和TLS 1.2,第1张

Java HttpsURLConnection和TLS 1.2

您将必须 在 Java 1.8中 创建一个

SSLContext
用于设置Protocoll的协议


 SSLContext sc = SSLContext.getInstance("TLSv1.2"); // Init the SSLContext with a TrustManager[] and SecureRandom() sc.init(null, trustCerts, new java.security.SecureRandom());

Java 1.7中

 SSLContext sc = SSLContext.getInstance("TLSv1"); // Init the SSLContext with a TrustManager[] and SecureRandom() sc.init(null, trustCerts, new java.security.SecureRandom());

那么您只需将 SSLContext 设置HttpsURLConnection

httpsCon.setSSLSocketFactory(sc.getSocketFactory());

这应该够了吧。



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5600645.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存