How do I ignore http certificate errors? Currentl...
# ktor
g
How do I ignore http certificate errors? Currently this is what I have:
Copy code
private fun client(): HttpClient = HttpClient(CIO) {
    install(Logging) {
        level = LogLevel.ALL
        logger = Logger.DEFAULT
    }
    engine {
        proxy = ProxyBuilder.http("<http://0.0.0.0:8888/>")
    }
}
Already tried setting
trustManager
as described here https://ktor.io/docs/client-ssl.html#cio but
trustManager
does not exists and can't import. Same is written here https://stackoverflow.com/a/69162766/4885394 but yeah, I got no
trustManager
or sslContext
b
Copy code
val trust = 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
}

fun client() = HttpClient(CIO) {
    engine {
        https {
            trustManager = trust
        }
    }

    install(ContentNegotiation) {
        json(
            Json {
                serializersModule = jsonSerializersModule
                encodeDefaults = true
                ignoreUnknownKeys = true
                coerceInputValues = true
            },
        )
    }
}
I use same way with stackoverflow
g
ahh, my bad. I was writing this code in commonTest and that's why it did not show those options
220 Views