Hi, I am using .ktor and okhttp engine. And got ex...
# ktor
n
Hi, I am using .ktor and okhttp engine. And got exception certpathvalidatorexception when we tried to migrate to https, can I use ktor fot https? And if ‘yes’ where start searching to solve my issue, I think it’s because we use some like backend developers says ‘custom certificate’.
e
Hi @Nikolai, ktor supports http with
okhttp
at
okhttp
level.
n
@e5l Thank you for response! But at the end author create OkHttp client and RestAdapter, how can I create it using ktor?
e
You could configure or replace
okhttp
instance in
OkHttpConfig
n
But it should be done in Android module not in common?
e
😞 It’s sad but true. We have no common
tls
configuration for now.
n
So, if I use
Copy code
private val client = HttpClient {
        expectSuccess = false
        install(JsonFeature) {
            serializer = KotlinxSerializer()
        }

    }
Copy code
GlobalScope.launch(CoroutineContextProvider.provideContext()) {
            try {
                val call = client.request<HttpResponse> {
                    url {
                        protocol = serverProtocol
                        host = serverAddress
                        port = serverPort
                        encodedPath = requestEncodedPath
                    }
                    method = <http://HttpMethod.Post|HttpMethod.Post>
                    body = requestBody

                    for (currentPair:Pair<String, String> in requestHeaders) {
                        headers.append(currentPair.first, currentPair.second)
                    }
                    headers.append(apiVersionHeader, apiVersion)
                    for (currentPair:Pair<String, String> in parameters) {
                        parameter(currentPair.first, currentPair.second)
                    }
                }
                requestResponseHandler(call, call.readText())
            } catch (requestException:Exception) {
                requestExceptionHandler(requestException)
            }
        }
This client initialization in common module and sending requests api. Is there any way how I can still use it, but may be provide some config for OkHttp, from actual class implementations? Without rewriting too much code?
e
You can construct
HttpClient
in
expect fun
. Also you can search for the multiplatform DI framework.
n
Thanks a lot
😉 1
b
Hey how do I set the favicon through HTML DSL