I would like to connect to a https trusted site on a internal LAN.
I tried with :
public static void main(String args[]) throws IOException {
OkHttpClient client = new OkHttpClient();
RequestBody formBody = new FormBody.Builder()
.add("user", "password")
.build();
Request request = new Request.Builder()
.url("https://contoso.com")
.post(formBody)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.code());
But that resulted in PKIX Path Building Error, ValidatorException: unable to find valid certificate path to requested target.
The link above suggested adding:
System.setProperty("javax.net.ssl.trustStore", "cacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "password");
But this generates a new error:
javax.net.ssl.SSLException: javalang.RunTimeException: UnexpectedError: java.security.InvalidAlgoritmParameterException: the trustedAnchors parameter must be non empty
I also tried to force using cacerts by executing the fatjar with :
java -jar TestClient.jar -Djava.net.ssl.trustStore="\path\to\cscerts\in\java\lib\security\cacerts"
But I still eventually get `the trustAnchors parameter must be non empty'
If I try with https://www.google.com - it works fine. Java is also being set to use the network proxy.
How can I fix this error to make a connection to this site?