Sometimes it is needed to allow insecure HTTPS connections, e.g. in some web-crawling applications which should work with any site. I used one such solution with old HttpsUR
With Java 11, as well you can do a similar effort as mentioned in the selected answer in the link shared with the HttpClient built as:
HttpClient httpClient = HttpClient.newBuilder()
.connectTimeout(Duration.ofMillis( * 1000))
.sslContext(sc) // SSL context 'sc' initialised as earlier
.sslParameters(parameters) // ssl parameters if overriden
.build();
with a sample request
HttpRequest requestBuilder = HttpRequest.newBuilder()
.uri(URI.create("https://www.example.com/getSomething"))
.GET()
.build();
can be executed as:
httpClient.send(requestBuilder, HttpResponse.BodyHandlers.ofString()); // sends the request
Update from comments, to disable the hostname verification, currently one can use the system property:
-Djdk.internal.httpclient.disableHostnameVerification
which can be set programmatically as following :-
final Properties props = System.getProperties();
props.setProperty("jdk.internal.httpclient.disableHostnameVerification", Boolean.TRUE.toString());