How to connect to TLS 1.2 enabled URL using HTTP POST Method.
If your application runs on Java 1.7 or Java 1.6 (update 111 or later), you can set the https. protocols system property when starting the JVM to enable additional protocols for connections made using the HttpsURLConnection class – for example, by setting -Dhttps. protocols=TLSv1. 2 .
TLS 1.2 is automatically enabled in Google Chrome version 29 or greater.
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 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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With