Today in the use of httpClient4.3.6 analog landing on the HTTPS website, there is a certificate error, this is in the open source Chinese community found in the feasible answer (original link: http://www.oschina.net/question/194048_ 135225?sort=time)
Presumably the logic is that you've achieved trust in all certificates
ImportJavax.net.ssl.SSLContext;Importorg.apache.http.conn.ssl.SSLConnectionSocketFactory;ImportOrg.apache.http.conn.ssl.SSLContextBuilder;ImportOrg.apache.http.conn.ssl.TrustStrategy;Importorg.apache.http.impl.client.CloseableHttpClient;Importorg.apache.http.impl.client.HttpClients;/** * * @authorSayi **/ Public Abstract classSslutils { Public Staticcloseablehttpclient createsslinsecureclient () {Try{sslcontext Sslcontext=NewSslcontextbuilder (). Loadtrustmaterial (NULL,NewTruststrategy () {//Trust all Public Booleanistrusted (x509certificate[] chain, String authtype)throwscertificateexception {return true; }}). Build (); Sslconnectionsocketfactory SSLSF=Newsslconnectionsocketfactory (Sslcontext); returnHttpclients.custom (). Setsslsocketfactory (SSLSF). build (); } Catch(keymanagementexception e) {e.printstacktrace (); } Catch(nosuchalgorithmexception e) {e.printstacktrace (); } Catch(keystoreexception e) {e.printstacktrace (); } returnHttpclients.createdefault (); } }
Reprint-Solve the problem of certificate error when using httpclient 4.3.x to login HTTPS