Hostname in certificate didn't match?

前端 未结 5 1104
挽巷
挽巷 2020-12-13 11:37

I try to connect to a server with a self-signed certificate. I use this code to accept all certificates.

public class CertificateAcceptor {

    public void          


        
5条回答
  •  温柔的废话
    2020-12-13 12:19

    You may use SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER

    SSLSocketFactory sf = new SSLSocketFactory(
        SSLContext.getInstance("TLS"),
        SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    Scheme sch = new Scheme("https", 443, sf);
    httpclient.getConnectionManager().getSchemeRegistry().register(sch);
    
    HttpGet httpget = new HttpGet("https://host/");
    ...
    ...
    

提交回复
热议问题