我如何为KTOR HTTPclient Multiplatform Kotlin项目配置引擎?还需要添加SSL证书

问题描述 投票:0回答:1

下面是我尝试过的代码。我正在commonMain块中尝试以下代码。

suspend fun callHttpFunction(){

val clientEngine = HttpClient{

        engine {
            pipelining = true
            threadsCount = 4
        }

    }

    clientEngine.post<String>("https","m2.testing.com",8080,
        "/TokenServiceEncrypt/api/base/TokenUpdated",requestBlock
    ) {
        headers.append("Content-Type", "application/json")
        headers.append("Accept", "application/json")
        headers.append("SessionToken", "seesfssfsf")
    }
    clientEngine.close()
}

//HttpClient(Apache) fails and so does HttpClient(OkHttp)
kotlin httpclient multiplatform ktor
1个回答
0
投票

无法在公共块中添加Apache,OkHttp或CIO引擎-这三个特定于JVM。但是,将它们添加到JVM / Android源集中应该没有问题。同样,“对于JVM,默认引擎由ServiceLoader解析,第一个可用引擎按字母顺序排序。这取决于您所包含的工件。” (底部的链接)。

List of engines by platform

这意味着,除非您需要自定义引擎配置,否则无需显式初始化,只要将它们以正确的顺序放置(对于JVM),对于iOS,实际上没有任何选择,只有一个内置in选项将被自动拾取并在内部使用NSUrlSession。

Ktor Engines and where they belong:

© www.soinside.com 2019 - 2024. All rights reserved.