SSLSocketFactory.getSocketFactory().setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SSLContext contextvolley = null; try { contextvolley = SSLContext.getInstance("TLS"); contextvolley.init(null,new X509TrustManager[]{new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { } @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } @Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } }},new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(contextvolley.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier(new NullHostNameVerifier()); } catch (Exception e) { e.printStackTrace(); }
public static class NullHostNameVerifier implements HostnameVerifier { @Override public boolean verify(String hostname, SSLSession session) { //android.util.Log.e("RestUtilImpl", "Approving certificate for " + hostname); return true; } }