Hi, I’m stuck in adding interceptor and Certificat...
# ktor
a
Hi, I’m stuck in adding interceptor and CertificatePinner in Default Engine of Ktor i.e.
HttpClient()
I came to know, that I can do it using HttpClient(OkHttp) engine, but in KMM project, I’m not allowed to add OkHttp dependency in shared/commonMain module. It’s saying
Copy code
Failed building KotlinMPPGradleModel
org.gradle.internal.resolve.ArtifactNotFoundException: Could not find ktor-client-okhttp-1.6.0-samplessources.jar (io.ktor:ktor-client-okhttp:1.6.0).
//Something I’ve achieve yet.
Copy code
var cert : CertificatePinner = CertificatePinner.Builder()
    .add(baseURL, "***************")
    .build()

val ktorHttpClient = HttpClient(OkHttp) {
    engine {
        config {
            certificatePinner(cert)
        }
    }
What I need
Copy code
val ktorHttpClient = HttpClient() {

    engine {
        //ADD CERTIFICATE PINNER
        //ADD INTERCEPTOR
    }
e
Please add OkHttp client to shared/androidMain, and make an expect/actual class/function to export your Engine to the commonMain.
✔️ 1
a
Good idea. Hope It’ll work for me. Thanks a lot.
It worked 😄 I did something like this
Copy code
expect class KtorClientProvider() {
    val ktorClient: HttpClient
}
Thanks again @El Zhang
👍 1