Android 带有自签名 SSL 证书问题的 HTTPS... 解决方案或更好的方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2740975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:10:42  来源:igfitidea点击:

HTTPS with Self-Signed SSL Certificate Issues... Solution or better way?

androidhttpsdownloadself-signed

提问by stormin986

All I need to do is download some basic text-based and image files from a web server that has a self-signed SSL certificate.

我需要做的就是从具有自签名 SSL 证书的 Web 服务器下载一些基本的基于文​​本和图像的文件。

I have been trying to figure out how to use HttpClient to do this, but getting the SSL to work is a nightmare that seems to be way too much trouble for such a simple task.

我一直试图弄清楚如何使用 HttpClient 来做到这一点,但让 SSL 工作是一场噩梦,对于这样一个简单的任务来说似乎太麻烦了。

Is there a better way to perform these file downloads? Perhaps through a WebView or Browser feature? Reinventing the wheel of making a simple HTTPS GET request is a major pain, and is significantly holding up my development schedule.

有没有更好的方法来执行这些文件下载?也许通过 WebView 或浏览器功能?重新发明一个简单的 HTTPS GET 请求是一个主要的痛苦,并且严重阻碍了我的开发计划。

采纳答案by stormin986

I found two great examples of how to accept self-signed SSL certificates, one each for HttpsURLConnection and HttpClient.

我发现了两个关于如何接受自签名 SSL 证书的很好的例子,一个分别用于 HttpsURLConnection 和 HttpClient。

HttpsURLConnection solution:Https Connection Android

HttpsURLConnection 解决方案:Https Connection Android

HttpClient solution:Self-signed SSL acceptance on Android

HttpClient 解决方案:Android 上的自签名 SSL 接受