Note that there are some explanatory texts on larger screens.

plurals
  1. POUrlConnection not opening HttpsUrlConnection
    primarykey
    data
    text
    <p>I'm trying to connect to secure http via Java Embedded Machine.</p> <p>i have running self signed apache server on port 8090. When i use web browser to navigate to <code>https://myserver:8090</code> it shows self signed certificate warning and loads ok.</p> <p>I have this code</p> <pre><code> URL dstUrl = new URL("https://myserver:8090") URLConnection result = dstUrl.openConnection(); System.out.println("Protocol: "+dstUrl.getProtocol()+", is HTTPS:"+(result instanceof HttpsURLConnection)); // Echo: Protocol HTTPS is HTTPS:false if (result instanceof HttpsURLConnection) {//will not reach try { HttpsURLConnection conn = (HttpsURLConnection) result; conn.setSSLSocketFactory(sslContext.getSocketFactory()); conn.setHostnameVerifier(defaultHostVerifier); } catch (Exception e) { //sout will not ignate } } return (HttpURLConnection) result; </code></pre> <p>This code should function fine but the openConecction() will allways return HttpUrlConnection and not HttpsUrlConnection. Is there any chance i can force opening HttpsUrlConnection if i know that protocol is https?</p> <p>EDIT:</p> <p>My Imports:</p> <pre><code>import java.io.IOException; import java.net.HttpURLConnection; import java.net.URI; import java.net.URL; import java.net.URLConnection; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; </code></pre> <p>EDIT 2:</p> <p>I've found out on the issuers site that there should be a <code>URLStreamHandlerFactory</code> applied at start of machine so https protocol is returned by deprecated <code>com.sun.net.ssl.internal.www.protocol.https.Handler</code></p> <p>now i know that HttpsUrlConnection by javax is not returned but a <code>com.sun.net.ssl.HttpsUrlConnection</code></p> <p>Thanks anyway</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload