[Ktor-Client] Is there a way to get String version...
# ktor
j
[Ktor-Client] Is there a way to get String version of Request Body even the body is supplied from Object and using JsonFeature? I have need to get the body and create signature from it and send it as headers.
e
You could try:
Copy code
val response = client.get<HttpResponse>(...)
// check the status and etc
response.receive<MyDataClass>()
j
No, I mean when I want to send client request in the first place. Something like this https://gist.github.com/jasoet/dd455ad369e03cd6f0a3df93f06fd6e8
@e5l ^^
https://gist.github.com/jasoet/dd455ad369e03cd6f0a3df93f06fd6e8#file-ktorreq-kt-L11-L15 For now my code only support String as Content-Type or when body is empty If body is Object, It will be hard to know the exact String that sent to server
Basically, I want to intercept body after rendered by JsonFeature, and create header from that.
e
And you actually could insert interceptor after Json feature
j
Let me try that
@e5l Could you direct me to Docs or Source related to Ktor Client Interceptor?
e
You could look into Json feature for the ‘requestPipeline’. Its the stuff related to the feature implementation: http://ktor.io/clients/http-client/features.html
So you could take a look on client features as the example
j
@e5l thanks
e
No problem. Feel free to ask if you have any questions
j
@e5l Thanks a lot for your helps. My Code is working fine and then I created Ktor Client features for Chef API Client Auth. Still need work for Readme and Test. You can check here. Feedback are welcome 😄 https://github.com/jasoet/ktor-client-chef
138 Views