• The previous network request framework is HongyangokHttputils, the network request using HTTPS on 5.0 mobile phones is no problem, but recently suddenly used a 4.4 system, error SSLException…. Zha zha ground

  • Then our VP found us a blog on how to solve the problem with the 4.+ system (although I’m still a little confused…). , and then add it and it’s ready to use. Both Okgo and OkHttpUtils work, so should network requests work as well? !!!!! – then I’ll post a link to that guy’s blog, using TLSSocketFactory

  • And then we’re going to use this class at global initialization, that second argument, whatever it provides. ··· OkHttpClient OkHttpClient = null; try { HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(null, null, null); okHttpClient = new OkHttpClient.Builder() .addInterceptor(new LoggerInterceptor(“history”)) .sslSocketFactory(new TLSSocketFactory(), sslparams.trustManager)// used here!! .build(); } catch (KeyManagementException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } OkHttpUtils.initClient(okHttpClient); …

  • The same is true with OKgo. The second parameter is posted below if you don’t want to use the frame itself.

  • This is TSsX509TrustManager…

public class SsX509TrustManager implements X509TrustManager { private static TrustManager[] trustManagers; private static final X509Certificate[] _AcceptedIssuers = new X509Certificate[]{};

@Override public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException { //To change body of implemented methods use File | Settings |  File Templates. } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException { //To change body of implemented methods use File | Settings |  File Templates. } @Override public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new java.security.cert.X509Certificate[0]; } public boolean isClientTrusted(X509Certificate[] chain) { return true; } public boolean isServerTrusted(X509Certificate[] chain) { return true; } public static X509Certificate[] get_AcceptedIssuers() { return _AcceptedIssuers; } /** * allow all SSL requests, Add in the new StringRequest before () * / public static void allowAllSSL () {HttpsURLConnection. SetDefaultHostnameVerifier (new HostnameVerifier() { @Override public boolean verify(String arg0, SSLSession arg1) { // TODO Auto-generated method stub return true; }}); SSLContext context = null; if (trustManagers == null) { trustManagers = new TrustManager[]{new SsX509TrustManager()}; } try { context = SSLContext.getInstance("TLS"); context.init(null, trustManagers, new SecureRandom()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory()); }Copy the code

}