Self-signed certificate and loopj for Android

前端 未结 6 452
太阳男子
太阳男子 2021-01-30 15:08

I\'m trying to use loopj for making async HTTP requests. Works great, except when I try to access https site with self-signed cert. I get

6条回答
  •  庸人自扰
    2021-01-30 15:49

    Simpler way is to use built-in MySSLSocketFactory in loopj, so you don't have to create another class

    try {
            KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
            trustStore.load(null, null);
            MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
            sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            client.setSSLSocketFactory(sf);
    }
    catch (Exception e) {}
    

提交回复
热议问题