https://kotlinlang.org logo
Title
j

João Pedro De Melo Garrido

08/06/2021, 5:23 PM
Hello everyone, been developing a restapi with ktor and ran into a problem with kors, on postman works fine but when i try doing it from website with fetch and javascript it runs into an error saying that "cannot convert from text/plain" even when im using fetch with content type application/json and when i have gson on my ktor server
install(CORS) {
    method(HttpMethod.Get)
    method(<http://HttpMethod.Post|HttpMethod.Post>)
    method(HttpMethod.Put)
    method(HttpMethod.Delete)
    method(HttpMethod.Head)
    method(HttpMethod.Options)
    header(HttpHeaders.AccessControlAllowHeaders)
    header(HttpHeaders.AccessControlAllowOrigin)
    header(HttpHeaders.Authorization)
    allowCredentials = true
    allowSameOrigin = true
    anyHost()
}
this is my cors and when i add this line works (obvs cause it accepts text/plain) but dont understand whats happening
allowNonSimpleContentTypes = true
j

Jilles Soeters

08/06/2021, 6:30 PM
Request application/json doesn’t matter if you respond with text/plain