Setup AsyncHttpClient to use HTTPS

前端 未结 3 741
一整个雨季
一整个雨季 2020-12-05 06:27

I am using com.loopj.android:android-async-http:1.4.9 for my request to server. It was working fine until I SSL/TLS is required in my server. So I need to modif

3条回答
  •  孤城傲影
    2020-12-05 06:38

    you can use @Prerak's solution. Looks like that solution works. This is my own version. It is similar to @Prerak's but a shorter constructor:

    public CustomSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
        super(truststore);
    
        // Create a TrustManager that trusts the CAs in our KeyStore
        String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
        tmf.init(truststore);
    
        // Create an SSLContext that uses our TrustManager
        sslContext.init(null, tmf.getTrustManagers(), null);
    }
    

提交回复
热议问题