Reprint-Solve the problem of certificate error when using httpclient 4.3.x to login HTTPS

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.