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

Shan

10/17/2019, 10:46 PM
I get this error:
Request of type HttpMethod(value=GET) couldn't send a body with the Android engine.
I see that specifically on the Android engine I cannot send a GET request with an empty body but am unsure of the reasoning for this.
e

e5l

10/18/2019, 10:16 AM
Hi @Shan, thanks for the notice. Could you provide the use case of the empty body? Probably we can allow this special case, but there is no difference between
absent
and
empty
here.
btw
Android
engine uses
UrlConnection
under the hood.
s

Shan

10/18/2019, 7:33 PM
The issue was from setting the ContentType in my default request (
contentType(ContentType.Application.Json)
). When making a GET request with the ContentType as Json it adds an empty
{}
to the body (even when not setting the body at all, or manually setting it to NoContent) which makes the body appear to have something inside of it I suppose. I did a manual
if (method != HttpMethod.Get) contentType(ContentType.Application.Json)
in my default HttpRequestBuilder block and it is working alright now, though I'm not sure that's intended behavior.
9 Views