Hi there, I'm here to step up my kotlin specializa...
# ktor
f
Hi there, I'm here to step up my kotlin specialization! I have a lot of questions to post! but for now, I'm looking for a good example of to how use properly ktor client response validation... can someone post me something? Thanks!
a
Here is the documentation.
f
Is not my first time on documentation, spent about 1 day looking for a solution... but when I call receive in the validator, i can't read it another time... the validator consume the stream.. and i don't know how to avoid that.. (in detail some time this backend give me a 200, with an error message inside, so i need to read the response in validator and throw if is a real error, or nothing otherwise....
l
Save the value and read the data from the value you saved previously.
a
You can make a copy of the request, response, and call objects by executing the
save
method on the
HttpClientCall
instance. Here is an example:
Copy code
val client = HttpClient(Apache) {
    HttpResponseValidator {
        validateResponse { response ->
            val originCall = response.call
            val newCall = originCall.save()
            val text = newCall.response.readText()
            println(text)
        }
    }
}

client.get<String>("<http://example.com>")
f
Here again, sorry but as Boromir teaches Is Not That simple (problem is that I'm not that skilled).. here is the snippet, and the log after first HTTP response is received, and finally the request... it looks like I'm missing to understand something
image.png
Any ideas?
a
For some reason, Gson converted a JSON to the
null
.