日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android 4 +https(如何启动TLS1 1 and TLS1 2)

發(fā)布時間:2023/12/6 Android 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android 4 +https(如何启动TLS1 1 and TLS1 2) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
  • 之前用的網(wǎng)絡(luò)請求框架是鴻洋的OkHttpUtils,網(wǎng)絡(luò)請求在5.0手機上使用https沒有問題,但是最近突然使用了一個4.4的系統(tǒng),就報錯SSLException ....咋地咋地

  • 然后 我們的副總給我們找一個博客,如何解決4.+系統(tǒng)出現(xiàn)的這個問題(雖然我現(xiàn)在還很有點懵逼...),然后添加上去后,就可以使用了。在Okgo ,OkHttpUtils 都可以用,那么的網(wǎng)絡(luò)請求應(yīng)該也可以用?!!(別的沒有測) -然后我先貼一下那個仁兄的博客吧 鏈接地址 ,使用TLSSocketFactory 類

  • 然后就是在全局初始化的時候使用這個類 , 那個第二次參數(shù),就用他提供的。 ··· 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)//這里使用!!! .build(); } catch (KeyManagementException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } OkHttpUtils.initClient(okHttpClient); ···

  • 用OKgo也一樣的,第二個參數(shù)如果不想用框架自帶的我在下面貼出來。

  • 這是 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; }/*** 允許所有的SSL請求,添加在new StringRequest()之前*/ public static void allowAllSSL() {HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {@Overridepublic boolean verify(String arg0, SSLSession arg1) {// TODO Auto-generated method stubreturn 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()); } 復(fù)制代碼

}

···

總結(jié)

以上是生活随笔為你收集整理的Android 4 +https(如何启动TLS1 1 and TLS1 2)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。