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

gotoOla

09/26/2018, 1:48 PM
Hey! Running into a silly problem. I want to set the Content-Type to application/json but I don’t want to use the serialization of jackson or gson. When I set the content-type in the request itself I get a UnsafeHeaderException and it states that it should be set from the engine
The idea is to set the content-type along the response
For example:
call.respondText("p { background: red; }", contentType = ContentType.Text.CSS, status = HttpStatusCode.OK)
g

gotoOla

09/26/2018, 1:51 PM
this is in an httpClient, so we do a client.post like this val response = client.post<HttpResponse>(updateUrl) { body = payload contentType(ContentType.Application.Json) }
d

Deactivated User

09/26/2018, 1:51 PM
oh I see
g

gotoOla

09/26/2018, 1:51 PM
so it’s not server side on the response-part
d

Deactivated User

09/26/2018, 1:52 PM
https://ktor.io/clients/http-client/calls/requests.html#specifying-a-body-for-requests
Copy code
body = TextContent("HELLO WORLD!", ContentType.Text.Plain)
?
the content type is still part of the
OutgoingContent
, so when you generate one, you have to specify it there
g

gotoOla

09/26/2018, 1:53 PM
ah I see, this looks like what I am after
👍 1
wkr
worked splendidly. Thanks for the help!
2 Views