gpt4 book ai didi

kotlin - 如何禁用 Ktor 客户端 SSL 验证?

转载 作者:行者123 更新时间:2023-12-04 13:09:57 25 4
gpt4 key购买 nike

我正在尝试从仅在原型(prototype)设计期间存在的内部测试环境连接到具有自签名证书的服务。 Ktor 客户端失败

javax.net.ssl.SSLHandshakeException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target

在这种情况下如何禁用证书验证?

最佳答案

这是我的CIO引擎解决方案。

val client = HttpClient(CIO) {
engine {
https {
trustManager = object: X509TrustManager {
override fun checkClientTrusted(p0: Array<out X509Certificate>?, p1: String?) { }

override fun checkServerTrusted(p0: Array<out X509Certificate>?, p1: String?) { }

override fun getAcceptedIssuers(): Array<X509Certificate>? = null
}
}
}
}

关于kotlin - 如何禁用 Ktor 客户端 SSL 验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66490928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com