当我尝试从我的应用程序访问“https”网络服务时,它给出了“javax.net.ssl.SSLHandshakeException:连接被对等方关闭' 错误。相同的 Web 服务在 Chrome 浏览器中运行良好。
此问题仅在 Android 7.0 上出现,在 Android 6.0 和 5.0 上运行良好。
服务器经过 CA 认证,而非自签名。
尝试使用此代码,它对我有用:
private static void initializeSSLContext(Context mContext){
try {
SSLContext.getInstance("TLSv1.2");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
try {
ProviderInstaller.installIfNeeded(mContext.getApplicationContext());
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
并且不要忘记使用谷歌安全库:
compile 'com.google.android.gms:play-services-safetynet:11.6.2'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)