Ktor HttpClient 对分块传输编码的支持

Mic*_*dge 6 httpclient chunked-encoding kotlin ktor

我正在使用 Ktor HttpClient(CIO) 向 HTTP API 发出请求,该 API 的响应使用分块传输编码。

在调用使用分块传输编码的 API 时,是否可以使用 Ktor HttpClient(CIO) 来访问 HttpResponse 中的各个 Http 块?

小智 0

我想迟到总比不到好:

httpClient.prepareGet("http://localhost:8080/").execute {
    val channel = it.bodyAsChannel()
    while (!channel.isClosedForRead) {
        val chunk = channel.readUTF8Line() ?: break
        println(chunk)
    }
}
Run Code Online (Sandbox Code Playgroud)