The HTTPS Web server is a certificate. is issued by the website's own server and is not widely accepted by the browser or operating system.
when using Closeablehttpclient often encounter certificate errors (this is how the website is known)
Now requires SSL bypass certificate, the following directly paste the code, the call only need to send the request after the new Httpsberber (the file's byte code);
1 ImportJavax.net.ssl.HostnameVerifier;2 Importjavax.net.ssl.HttpsURLConnection;3 Importjavax.net.ssl.SSLSession;4 ImportJava.util.logging.Logger;5 6 Public classHttpsberber {7 PublicHttpsberber (String name)throwsException {8Logger =Logger.getlogger (name);9 trustallhttpscertificates ();Tenhostnameverifier HV =NewHostnameverifier () { One Public BooleanVerify (String urlhostname, sslsession session) { ALogger.info ("Warning:url Host:" + urlhostname + "vs." +session.getpeerhost ()); - return true; - } the }; - httpsurlconnection.setdefaulthostnameverifier (HV); - } - Private StaticLogger Logger; + Private Static voidTrustallhttpscertificates ()throwsException { -javax.net.ssl.trustmanager[] Trustallcerts =NewJavax.net.ssl.trustmanager[1]; +Javax.net.ssl.TrustManager TM =NewMiTM (); ATrustallcerts[0] =TM; atJavax.net.ssl.SSLContext sc =Javax.net.ssl.SSLContext -. getinstance ("SSL"); -Sc.init (NULL, Trustallcerts,NULL); - Javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory (SC - . Getsocketfactory ()); - } in Static classMiTMImplementsJavax.net.ssl.TrustManager, - Javax.net.ssl.X509TrustManager { to Publicjava.security.cert.x509certificate[] Getacceptedissuers () { + return NULL; - } the * Public Booleanisservertrusted ( $ java.security.cert.x509certificate[] certs) {Panax Notoginseng return true; - } the + Public Booleanisclienttrusted ( A java.security.cert.x509certificate[] certs) { the return true; + } - $ Public voidcheckservertrusted ( $ java.security.cert.x509certificate[] certs, String authtype) - throwsjava.security.cert.CertificateException { - return; the } - Wuyi Public voidcheckclienttrusted ( the java.security.cert.x509certificate[] certs, String authtype) - throwsjava.security.cert.CertificateException { Wu return; - } About } $}
Java Crawler--https Bypass certificate