implementation("io.ktor:ktor-client-cio:3.0.3")
package org.example
import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import kotlinx.coroutines.runBlocking
import java.time.LocalTime
fun main() {
runBlocking {
val client = HttpClient(CIO) {
install(HttpTimeout) {
requestTimeoutMillis = 10000
}
}
val requestTime = LocalTime.now()
val response: HttpResponse = client.get("https://www.baidu.com/") {
timeout {
requestTimeoutMillis = 30000
}
}
println("Request time: $requestTime")
println(response.bodyAsText())
}
}
标签:ktor,CIO,client,io,import,HttpClient
From: https://www.cnblogs.com/soarowl/p/18621061