关于webview 中使用https 链接 总是弹出认证ssl问题

来源:互联网 发布:vivo手机一键锁屏软件 编辑:程序博客网 时间:2024/06/07 01:16

             因为ios 所有链接必须使用https,所以android 对应的也升级了https,在测试环境中测试时候都是使用fiddler 代理手动认证证书,一直没有发现问题,到了线上环境的时候每次时候部分手机使用webview 访问https的时候总是弹框说证书安全问题需要认证。

            最开始以为是公司或者第三方的https证书没有认证,后来排除了,最后百度得到解决方法

WebView webview = (WebView) findViewById(R.id.webview);webview.setWebViewClient(new WebViewClient() {    @Override    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {        //handler.cancel(); 默认的处理方式,WebView变成空白页        //handler.process();接受证书        //handleMessage(Message msg); 其他处理    }});
重写onreceivedSslError方法 然后handler.process();代表接收证书,这样就不会弹出https认证了。


同时需要注意 android 5.0 以后会有http https 混合问题;解决方法如下

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {       webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);  }  

转载自http://blog.csdn.net/top_code/article/details/8998385

转载自http://blog.csdn.net/luofen521/article/details/51783914

0 0
原创粉丝点击