Android WebView SSL“安全警告" [英] Android WebView SSL 'Security Warning'

查看:50
本文介绍了Android WebView SSL“安全警告"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为客户构建应用的测试版本.此应用程序的一部分使用调用基于 SSL 的站点的 WebView.反过来,客户端提供了一个测试域,其中证书名称与 FQDN 不匹配.唉,他们无法提供匹配的证书.:(

I'm building a test version of an app for a client. Part of this app uses a WebView that calls out to a SSL-based site. In turn, the client has provided a test domain where the certificate name does not match the FQDN. Alas, they are not in a position to provision a cert that matches. :(

我正在使用一行代码在配套的 iOS ad hoc 应用程序上解决此问题(同样,不用于生产用途 - 仅用于测试目的).我已经在 Android 操作系统上搜索过类似的信息,但相比之下,我在这里和其他地方看到的解决方案足以让我头晕目眩!

I'm working around this issue on the companion iOS ad hoc app with one line of code (again, not for production use - just for test purposes). I have searched for similar info on Android OS, but the solutions I've seen here and elsewhere are enough to make my head spin big time by comparison!

有没有一种简单的方法来解决这个问题?甚至隐藏在某个地方的面向用户的设置?

Is there a straightforward way to work around this? Even a user-facing setting tucked away somewhere?

感谢线索!

推荐答案

创建一个 WebViewClient 并处理如下所示的 onReceivedSslError:

Create a WebViewClient and handle the onReceivedSslError which looks like this:

public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error)

在此回调中,您只需调用 handler.proceed() 即可继续加载页面.如果您不处理此回调并调用 proceed() 方法,则默认行为将是页面不加载.

Inside this callback you can just call handler.proceed() and the page will continue loading. If you don't handle this callback and call the proceed() method then the default behaviour will be for the page not to load.

这篇关于Android WebView SSL“安全警告"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆