0

please find below code snippet where I'm trying to connect the server for the REST call using the HttpsURLConnection

I'm geeting error while doing inputstream on the HttpsURLConnection's object.

I don't the how can I connect HTTPS sevrer.


  private String historyServerAddress
  private URL historyServerURL
  private String requestMethod
  private HttpsURLConnection httpURLConnection
  private String requestProperty

  Connection createConnection(String historyServerAddress) {

    System.setProperty("javax.net.ssl.trustStoreType","jks")
    System.setProperty("javax.net.ssl.trustStore","ssl_truststore")
    System.setProperty("javax.net.ssl.trustStorePassword","*****")
    this.historyServerURL = new URL(historyServerAddress)
    this.httpURLConnection = (HttpsURLConnection) this.historyServerURL.openConnection()
    SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory
        .getDefault();
    SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket(
        "10.200.104.97", 19890)

    sslsocket.startHandshake()
    httpURLConnection.setSSLSocketFactory(sslsocketfactory)

  }

}```
Pash0002
  • 110
  • 2
  • 14
  • Better to fix certificate on server. It must have subject alternative names. Or disable certificate checking on client https://stackoverflow.com/questions/19540289/how-to-fix-the-java-security-cert-certificateexception-no-subject-alternative – daggett Mar 22 '21 at 11:47
  • @daggett which certificate I need to add on the server? And where I can add this? – Pash0002 Mar 22 '21 at 13:16
  • 2
    here the certificate details of this server (stackoverflow.com) https://i.stack.imgur.com/57EUP.png the subject alternative name is missing on your server. "which certificate I need to add" - this question impossible to answer in comments - it requires a lot of details from you. – daggett Mar 22 '21 at 13:35

0 Answers0