I'm trying to get an HTML source code of a site.
My code:
public static void main(String[] args) {
URL url;
InputStream is;
try {
url = new URL("https://www.trackobot.com/");
is = url.openStream();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
But, when run this code, I get an exception:
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2023)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1125)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1546)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at java.net.URL.openStream(URL.java:1045)
at JsoupTutorial.ConnectToUrl.main(ConnectToUrl.java:24)
If I change the site, it work well, even with https sites like PayPal. But, still I have some sites that it just don't work and throw that exception. This site in the example is one of those sites that it don't work.
I searched for it and understand that I need to import the certificate of this site to the Java keystore. Am I correct?
My question is how Chrome do manage to enter those "Secure" sites ang get the HTML code? someone has to update (import) the certificate to the Chrome Cer database..who do this and when it happen? (Just in case that i'm correct above).
Anyway, I'm want to manage to load those sites perfect and receive the data I want. Where can I learn it from the basic?
Thank you.