Monitor a HTTPS connection with URL class (Java) -
I would like to monitor a simple URL but when an https server approaches me handshake exception Is it possible to verify the status of the https url for the browser used to use it? (Without a local certificate) I do not know how the browsers get content of URL from https, but I want to make it the same way. Without any need to store specific certificates for each server, anyone can be seen without the https.
try {url = new URL (row.getUrl ()); String protocol = u.getProtocol (); If (protocol. Angle ("https")) {HttpsURLConnection hc = (HttpsURLConnection) u.openConnection (); System.out.println ("Response Code:" + hc.getResponseCode ()); Hc.disconnect (); } If (protocol.equals ("http") {u.openConnection (); U.getContent (); } System.out.println ("url is up."); } Hold (exception e) {(...)}
If you really Don does not care about the legitimacy of the server's certificate, you want to set it which does not check anything, after that you have to set it to default so that the Trust Manager is used. Is when you use it. Here's an example:
TrustManager [] TrustArez = New TrustManager [] {New X509 Trust Manager () {Get the public X509 certificate [] Declined Issues () {return null; } Public Zero Check Client Trusted (X509 certificate [certs, string authType] {} Public Zero Checker Server Safe (X509 certificate [certs, string authType] {}}}; SSLContext sslctx = SSLContext.getInstance ("SSL"); Sslctx.init (null, trust e hari, empty); HttpsURLConnection.setDefaultSSLSocketFactory (sslctx.getSocketFactory ());
Using this technique, a complete example can be found. As the @Erikson says, this means that you can not tell if you are actually worried about the server you are worried about
Comments
Post a Comment