Android中访问证书有问题的SSL网页的方法
时间:2023-11-20 10:22:00
PC上的浏览器会弹出证书错误的对话框,提示你是否要无视错误继续浏览。实际上在WebView里也可以这样做,以实现加载证书有问题的页面。
WebView webview = (WebView) findViewById(R.id.webview);
webview.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
// *** NEVER DO THIS!!! ***
// super.onReceivedSslError(view, handler, error);
// let's ignore ssl error
handler.proceed();
}
}
只需像这样重载WebViewClient的onReceivedSslError()函数并在其中执行handler.proceed(),即可忽略SSL证书错误,继续加载页面。
这里要注意的是,千万不要调用super.onReceivedSslError()。这是因为WebViewClient的onReceivedSslError()函数中包含了一条handler.cancel()(见源码,其含义是停止加载,所以如果调用了super.onReceivedSslError(),其结果就是第一次访问时无法加载,第二次以后可以加载(不知道为什么),而且还可能发生libc的段错误:
A/libc: Fatal signal 11 (SIGSEGV) at 0x00000010 (code=1)
标签:Android,WebView
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
c#实现KTV点歌系统
2023-10-17 23:54:56
![](https://img.aspxhome.com/file/2023/9/100199_0s.png)
Spring Boot 集成Dubbo框架实例
2022-02-03 21:23:27
Spring Boot教程之提高开发效率必备工具lombok
2021-08-23 11:12:43
![](https://img.aspxhome.com/file/2023/9/61609_0s.png)
一问详解SpringBoot配置文件优先级
2023-01-08 05:40:14
![](https://img.aspxhome.com/file/2023/6/110886_0s.png)
使用java实现telnet-client工具分享
2023-10-18 10:56:59
简单了解SpringCloud运行原理
2023-06-09 17:07:15
Java实战之在线寄查快递系统的实现
2023-08-10 21:52:23
![](https://img.aspxhome.com/file/2023/2/58182_0s.png)
Android APP存活检测方式
2023-10-14 10:02:41
MyBatis字段名和属性名不一致的解决方法
2022-12-15 18:15:22
C# SkinEngine控件 给窗体添加皮肤的方法
2021-10-21 23:32:08
![](https://img.aspxhome.com/file/2023/5/102145_0s.jpg)
Android WebP 图片压缩与传输
2022-05-30 16:18:16
![](https://img.aspxhome.com/file/2023/8/130328_0s.jpg)
Android编程实现拍照功能的2种方法分析
2023-10-16 19:02:25
如何将写好的.py/.java程序变成.exe文件详解
2022-04-06 09:22:14
![](https://img.aspxhome.com/file/2023/1/70161_0s.png)
java基础的详细了解第七天
2023-02-01 12:06:26
![](https://img.aspxhome.com/file/2023/0/63700_0s.png)
JVM中的GC初识
2022-08-04 08:37:13
![](https://img.aspxhome.com/file/2023/5/113215_0s.jpg)
java通过ip获取客户端Mac地址的小例子
2021-12-22 06:37:07
Java 如何将网络资源url转化为File文件
2023-05-28 09:23:37
Android中的Launch Mode详情
2022-10-06 02:38:09
![](https://img.aspxhome.com/file/2023/3/125393_0s.webp)
java基础-数组扩容详解
2022-05-24 00:34:58
mybatis-plus自动生成代码的示例代码
2023-08-04 22:38:32