移除https错误忽略

This commit is contained in:
2024-11-24 19:58:53 +08:00
parent ca5629043b
commit 9fac012d11
2 changed files with 0 additions and 38 deletions

View File

@@ -23,32 +23,7 @@ fun getUnsafeOkHttpClient(
): OkHttpClient { ): OkHttpClient {
return try { return try {
// Create a trust manager that does not validate certificate chains // Create a trust manager that does not validate certificate chains
val trustAllCerts = arrayOf<TrustManager>(object : X509TrustManager {
@Throws(CertificateException::class)
override fun checkClientTrusted(
chain: Array<java.security.cert.X509Certificate>,
authType: String
) {
}
@Throws(CertificateException::class)
override fun checkServerTrusted(
chain: Array<java.security.cert.X509Certificate>,
authType: String
) {
}
override fun getAcceptedIssuers(): Array<java.security.cert.X509Certificate> = arrayOf()
})
// Install the all-trusting trust manager
val sslContext = SSLContext.getInstance("SSL")
sslContext.init(null, trustAllCerts, java.security.SecureRandom())
// Create an ssl socket factory with our all-trusting manager
val sslSocketFactory = sslContext.socketFactory
OkHttpClient.Builder() OkHttpClient.Builder()
.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager)
.hostnameVerifier { _, _ -> true } .hostnameVerifier { _, _ -> true }
.apply { .apply {
authInterceptor?.let { authInterceptor?.let {

View File

@@ -129,19 +129,6 @@ fun WebViewDisplay(modifier: Modifier = Modifier, url: String) {
AndroidView( AndroidView(
factory = { context -> factory = { context ->
WebView(context).apply { WebView(context).apply {
webViewClient = object : WebViewClient() {
override fun onReceivedSslError(
view: WebView?,
handler: SslErrorHandler?,
error: SslError?
) {
handler?.proceed() // 忽略证书错误
}
}
settings.apply {
domStorageEnabled = true
mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
}
loadUrl(url) loadUrl(url)
} }
}, },