I'm having a little encoding problem here, can som...
# ktor
r
I'm having a little encoding problem here, can someone point in the right direction? I have a simple route set up that simply sends the contents of the POST body back to the client:
Copy code
post("/reflect") {
    call.respondText(call.receiveText().also(::println))
}
When I send a request with special characters in it like this:
Copy code
POST <http://localhost:8080/reflect>
Content-Type: text/plain

ÄÖÜäöüßẞ
It comes out as a jumbled mess:
ÃÃÃäöüÃáº
And it get's printed to the console exactly like that as well, so the problem has to be on the receiving side, not the sending side. I'm not sure where to start looking what is going wrong here.
j
I think the default character set is ascii. Maybe try "Content-type: text/plain; charset=utf-8"
d
The fact that it gets printed to the console jumbled as well suggests that maybe your
kt
file is not in UTF-8.
r
Huh, setting the charset in the request worked. Is there any way to make Ktor assume that automatically if it's not set? Because I don't have control over all clients talking to my webservice to set that everywhere 😬
Ohhh, found an issue about that: https://github.com/ktorio/ktor/issues/384
Alright, got it figured out. This is intended behavior, but I managed to resolve it by using the ContentNegotiation feature directly instead of feeding the result of receiveText into my Jackson instance, which was a weird idea to begin with. Thanks @Jonathan Mew for giving me the right thing to put into google 😄
j
👍