https://kotlinlang.org logo
#ktor
Title
# ktor
t

tateisu

02/17/2022, 12:00 AM
Question about ktor-client. How to know there is response boby or not, before calling
HttpResponse.body()
?
a

Aleksei Tirman [JB]

02/17/2022, 2:37 PM
You need to read at least one byte to determine it:
Copy code
val channel = client.get<ByteReadChannel>("<http://example.com/>")
val hasBody = try {
    channel.readByte()
    true
} catch (_: ClosedReceiveChannelException) {
    false
}
Could you please explain why do you need it?
t

tateisu

02/19/2022, 10:53 PM
I was writing an API inspector. Anyway thank you.
2 Views