问题
How to connect to TLS 1.2 enabled URL using HTTP POST Method.
回答1:
Java 8
Java 8 will use TLS 1.2 by default
https://blogs.oracle.com/java-platform-group/jdk-8-will-use-tls-12-as-default
So for Java 8 all you need to do is the following.
import javax.net.ssl.*;
import java.net.URL;
URL url = new URL("https://www.google.com");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
Java 7
Java 7 needs to be set manually
import java.security.*;
import javax.net.ssl.*;
import java.net.URL;
URL url = new URL("https://www.google.com");
SSLContext ssl = SSLContext.getInstance("TLSv1.2");
ssl.init(null, null, new SecureRandom());
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setSSLSocketFactory(ssl.getSocketFactory());
来源:https://stackoverflow.com/questions/44788781/how-to-connect-to-tls-1-2-enabled-url-with-java