Ktor/Client
Ktor(Creating a client)
hik14
2022. 7. 13. 18:24
Ktor에는 Request을 만들고 Response을 처리하고 Auth, JSON 직렬화 등과 같은 플러그인으로 기능을 확장할 수 있는 다중 플랫폼 비동기 HTTP 클라이언트가 포함되어 있습니다.
intellJ 그림 설정대로 프로젝트 생성
JDK 18

gradle.properties
ktor_version=2.0.3
build.gradle.kts
val ktor_version: String by project
dependencies {
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-cio:$ktor_version")
}
Main.kt
1. client 엔진 설정.
2. get Request (url) 설정.
3. 상태 출력.
4. client 닫기.
fun main() = runBlocking {
val client = HttpClient(CIO)
val response: HttpResponse = client.get("https://ktor.io/")
println(response.status)
client.close()
}
