我试图连接到一个运行godaddy 256bit SSL证书的IIS6盒,但收到错误信息:

java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

我一直在试图确定是什么原因导致了这一点,但目前还没有定论.

以下是我的连接方式:

HttpsURLConnection conn;              
conn = (HttpsURLConnection) (new URL(mURL)).openConnection();
conn.setConnectTimeout(20000);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.connect();
String tempString = toString(conn.getInputStream());

推荐答案

@Chrispix的解决方案很危险!Trusting all certificates allows anybody to do a man in the middle attack!只需向客户发送任何证书,它就会接受!

将您的证书添加到自定义信任管理器,如本文所述:Trusting all certificates using HttpClient over HTTPS

虽然使用自定义证书建立安全连接有点复杂,但它将为您带来想要的SSL加密安全性,而不会有中间人攻击的危险!

Android相关问答推荐

Kotlin多平台向导,不兼容版本(ANP 8.2.0)ANP 8.1.2

CameraX与jetpack组成屏幕逻辑

如何使禁用状态下的material 3按钮与启用状态下的 colored颜色 相同?

strings.xml中字符串数组中的占位符

Android从已连接的设备获得GATT

Android布局渲染问题

Android 中 recyclerview 的自定义分隔线 colored颜色 不起作用

Android Compose 为什么 Checkbox 在父对象可点击时需要 onCheckChanged?

任务 ':app:kaptGenerateStubsDebugKotlin' 执行失败

Jetpack Compose 中带有权重的行和 AnimatedVisibility 会 destruct UI

Android apk 不工作

Jetpack Compose Arc 进度条动画(如何重启动画)

如何在 Android 应用程序未激活/未聚焦时显示视图?

GridLayout 和 GridView 有什么好用和区别

如何在 TextInputEdit 中调整可绘制对象的大小

Android WebView 没有在第一次页面完成时从本地存储读取数据?

如何在 Android Studio 中使用 Github Copilot?

为什么在try 实例化 Mediaplayer 时会出现 NullPointerException?安卓Kotlin

如何获取 Android Preferences DataStore 的所有键

Google API:java.lang.ClassNotFoundException:找不到类sun.misc.Service