https://kotlinlang.org logo
Title
b

brabo-hi

01/25/2022, 11:42 PM
Hi all, when using Ktor, how can i log
request Body
?
I am currently using
HttpClient {
        install(Logging) {
            level = LogLevel.ALL
        }
}
It is printing
response Body
not request
body
a

Aleksei Tirman [JB]

01/26/2022, 10:46 AM
Hey. Using the following code I can see the lines about request body in the log:
2022-01-26 13:45:54.467 [main] INFO  io.ktor.client.HttpClient - BODY START
2022-01-26 13:45:54.467 [main] INFO  io.ktor.client.HttpClient - My Body
2022-01-26 13:45:54.467 [main] INFO  io.ktor.client.HttpClient - BODY END
suspend fun main(): Unit = coroutineScope {
    val client = HttpClient(Apache) {
        install(Logging) {
            level = LogLevel.ALL
        }
    }

    val r = <http://client.post|client.post><String>("<https://httpbin.org/post>") {
        body = "My Body"
    }
    println(r)
}
1
b

brabo-hi

01/26/2022, 7:46 PM