Hi guys. I was trying to parse a request from a po...
# ktor
f
Hi guys. I was trying to parse a request from a post method using ContentNegotiation feature with GSON and it’s not working… Ktor produces
UnsupportedMediaTypeException
when try to parse the body. Do you know what i’m doing wrong? I just followed the documentation:
<https://ktor.io/servers/calls/requests.html#typed-objects>
Copy code
fun main() {
    embeddedServer(Netty, port = 8080, watchPaths = listOf(""), module = Application::module).start()
}

fun Application.module() {
    install(StatusPages) {
        exception<Throwable> {
            call.respondText(it.localizedMessage, ContentType.Text.Plain, HttpStatusCode.InternalServerError)
        }
    }
    install(ContentNegotiation) {
        gson()
    }
    routing {
        get("/") {
            call.respondText("Hello World", ContentType.Text.Html)
        }
        post("/verify") {
            val request = call.receive<Request>()
            call.respond(request)
        }
    }
}

data class Request(val userId: String, val productId: String)

data class Response(val status: String)
r
Could you post an example request you perform?
f
Sure!
Copy code
curl -v -H "Content-Type: application/json" -X POST -d '{"userId":"42","productId":"5"}' <http://localhost:8080/verify>