https://kotlinlang.org logo
Title
n

Nikolai

04/16/2019, 12:46 PM
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

e5l

04/16/2019, 1:06 PM
Hi @Nikolai, ktor supports http with
okhttp
at
okhttp
level.
n

Nikolai

04/16/2019, 1:11 PM
@e5l Thank you for response! But at the end author create OkHttp client and RestAdapter, how can I create it using ktor?
e

e5l

04/16/2019, 1:13 PM
You could configure or replace
okhttp
instance in
OkHttpConfig
n

Nikolai

04/16/2019, 1:22 PM
But it should be done in Android module not in common?
e

e5l

04/16/2019, 1:23 PM
😞 It’s sad but true. We have no common
tls
configuration for now.
n

Nikolai

04/16/2019, 1:29 PM
So, if I use
private val client = HttpClient {
        expectSuccess = false
        install(JsonFeature) {
            serializer = KotlinxSerializer()
        }

    }
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

e5l

04/16/2019, 2:02 PM
You can construct
HttpClient
in
expect fun
. Also you can search for the multiplatform DI framework.
n

Nikolai

04/16/2019, 2:09 PM
Thanks a lot
😉 1
b

brian

04/16/2019, 5:47 PM
Hey how do I set the favicon through HTML DSL