SSL Exception when using Volley

前端 未结 3 1140
孤城傲影
孤城傲影 2021-02-04 11:20

I\'m using Volley in Android to perform my app requests. Unfortunately, I\'m getting the following error:

com.android.volley.NoConnectionError: javax.net.ssl.SSL         


        
3条回答
  •  时光说笑
    2021-02-04 12:01

    After our comments maybe this can help you:

    Your requestQueue:

    static {
        requestQueue = Volley.newRequestQueue(Application.getContext(), new HurlStack(null, ClientSSLSocketFactory.getSocketFactory()));
    }
    

    The ClientSSLSocketFactory:

    public class ClientSSLSocketFactory extends SSLCertificateSocketFactory {
        private SSLContext sslContext;
    
        public static SSLSocketFactory getSocketFactory(){
            try
            {
                X509TrustManager tm = new X509TrustManager() {
                    public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {}
    
                    public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {}
    
                    public X509Certificate[] getAcceptedIssuers() {
                        return null;
                    }
                };
                sslContext = SSLContext.getInstance("TLS");
                sslContext.init(null, new TrustManager[] { tm }, null);
    
                SSLSocketFactory ssf = ClientSSLSocketFactory.getDefault(10000, new SSLSessionCache(Application.getInstance()));
    
                return ssf;
            } catch (Exception ex) {
                return null;
            }
        }
    
        @Override
        public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
            return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
        }
    
        @Override
        public Socket createSocket() throws IOException {
            return sslContext.getSocketFactory().createSocket();
        }
    }
    

提交回复
热议问题