最近几天我试图使用客户端证书通过webview访问网站。我使用了https://github.com/yonekawa/webview-with-client-certificate中的开源项目。在android 2.3.3平台上一切正常,我可以安装证书,在ssl错误调用
onReceivedSslError(WebView view, SslErrorHandler handler,
SslError error){
handler.proceed();}
然后
onReceivedHttpAuthRequest(final WebView view,
final HttpAuthHandler handler, final String host, final String realm)
被调用,我可以传递安全访问的凭据。
问题是4.x webview没有相同的行为,我必须创建一个包含所有内部类的自定义jar,请参见:https://github.com/yonekawa/webview-with-client-certificate/issues/1以便使用hiden方法
onReceivedClientCertRequest(WebView view,
ClientCertRequestHandler handler, String host_and_port)
问题是,方法被忽略得很好,项目被编译,但是方法永远不会被调用,相反,onreceivedsslerror像往常一样被调用,然后页面用白色页面完成加载,甚至不调用onreceivedhttpauthrequest,如2.3所示。
有没有人真正设法使上述例子为一个需要客户证书和授权的网站工作?
最佳答案
我确实看到了android 4.1.2上的事件。
我用clientcertificatewebview替换了webview,并加载了一个请求客户端证书的url。
https://github.com/yonekawa/webview-with-client-certificate/blob/master/res/layout/main.xml
按预期调用“onReceivedClientCertRequest”。
确保您的服务器实际上正在请求客户端证书。
关于android - Android Webview客户端证书和Http授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16564675/