Good day. I wrote server with ktor. Trying to sen...
# server
s
Good day. I wrote server with ktor. Trying to send DELETE request with body to the server and get 415 error. On Python server with Fast API the same request works. Could you advise me, what could be a problem, and how to fix it? The server snippet
Copy code
@Serializable
data class GroupData(
        @Contextual val  sessionId: String,
        @Contextual val  groupId: String
)
Copy code
delete("/api/v1/group") {
    val data = call.receive<GroupData>()
Copy code
...
}
The client snippet `return axios.delete(
${serverAddress}/api/v1/group
, { data: { sessionId: context.state.sessionId, groupId } }, )`
a
it would be helpful if you could share the server snippet and requst
415 would imply that the content type is incorrect or not accepted - check if json/xml type is allowed/accepted/properly formatted
check the content type header as well
s
Thank you, i added server and client snippet
a
do you have
Copy code
install(ContentNegotiation) {
    register(ContentType.Application.Json, JacksonConverter())
}
this?
also is the content type set properly?
s
I have
Copy code
install(ContentNegotiation) {
    json()
}
POST and PUT requests with json work correctly
a
can you print the request headers
s
IMG_20201118_235358_163.jpg
a
can you add a header
Content-Type
with value
application/json
s
Oh, I added and see, that request, made by axios, eventually does not have Content-Type Snippet is
Copy code
return axios.delete(
      ${serverAddress}/api/v1/group,
      {
        headers: {
          'Content-Type': 'application/json'
        },
        data: {
          sessionId: context.state.sessionId,
          groupId
        }
      },
    )
a
s
Ok, I write workaround for that on client side. And now the request works. Thank you!
Yes, I found the same link and took this workaround https://github.com/axios/axios/issues/1083#issuecomment-379509873 🙂
k
I think generally delete with body is in gray area and some servers/clients don't support it as it is not defined in spec