It is supposed to align, but I still get 415 form ...
# ktor
It is supposed to align, but I still get 415 form ktor. What am I doing wrong?
Which content negotiation module are you using?
For example, the Jackson content negotiation module is set to only parse JSON by default, as seen in the default parameter of its extension function:
If you take a look at, in the “basic usage” section they mention that you register different converters for different content types explicitly, so if you don’t have a converter set up for
you’ll get the 415 back
I'm using kotlinx.serialization
serialization { json() }
Alright, then you’ve registered a JSON converter in the content negotiator but not a converter for application/x-www-form-urlencoded. The content negotiation feature expects that if you’re just responding with an object that it has a converter which will convert the response into the appropriate type provided by the client’s “accept” header. After following this thread: it appears that you can sidestep the content negotiation feature by providing the already-serialized response via
like so:
Copy code
accept(ContentType.Application.FormUrlEncoded) {
            route("/api") {
                get("/test") {
                    println("Got message")
                    // Do stuff
                    val response = listOf("hello" to "world").formUrlEncode()
                    call.respondText(response, ContentType.Application.FormUrlEncoded)
The other option is to provide the content negotiation feature with a serializer that handles URL encoded content and converts it to and from objects
But those aren’t readily available to my knowledge
oh wait a sec
the contents of the request are url encoded, not the response
maybe my understanding of this feature is wrong
i want to accept url encoded requests
Yeah, you can do that. You just can’t use the Content Negotiation feature to deserialize the form encoded data into an object without a registered converter for that content type. If you want to just read the form encoded data as Ktor’s
object, you can do so via:
Copy code
Also, the
block you have is fine if you want to just have those endpoints receive form data. The effect will just be that if you try to hit it with a different content type it will respond with a 404 not found
thanks 👍