我正在构建一个网络和混合移动应用程序。这些应用程序使用ssl自签名证书与第三方服务通信,以实现env的暂存。桌面浏览器允许接受带有risk警告的无效cert,但在iOS应用程序中,我得到了此错误
Failed to load resource: The certificate for this server is invalid. You might be connecting to a server that is pretending to be "xxx" which could put your confidential information at risk.
我理解这种风险,但由于我的第三方提供者不能为临时服务器中的服务提供有效的ssl证书,所以我别无选择。
在iOS和android插件中是否存在允许无效ssl证书的信任/可能性。
真的很感谢你的帮助。
发布于 2019-06-04 02:17:30
在cordova-android@6.3.0中(以及更新的?)编辑SystemWebViewClient.java并编辑onReceivedSslError
,如大写注释中所示:
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
final String packageName = parentEngine.cordova.getActivity().getPackageName();
final PackageManager pm = parentEngine.cordova.getActivity().getPackageManager();
ApplicationInfo appInfo;
try {
appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
// debug = true
handler.proceed();
return;
} else {
// debug = false
// ADD THESE LINES TO IGNORE INVALID SSL CERTIFICATE
handler.proceed();
return;
// COMMENT THIS LINE:
//super.onReceivedSslError(view, handler, error);
}
} catch (NameNotFoundException e) {
// When it doubt, lock it out!
super.onReceivedSslError(view, handler, error);
}
}
现在,在调试和发布配置中,SSL证书错误都将被忽略。
这是取自这篇文章中的一个答案。
https://stackoverflow.com/questions/38863228
复制相似问题