Kotlin Fuel library - cannot send request without default header

523 views Asked by At

Fuel library - cannot send request without default header.

I'm trying to send exemplary request without Content-Type header:

Fuel.post("http://endpoint/...")
.also { it.headers.clear() }
.also { log.debug { "Headers: $it.headers" }}
.body("...body...".toByteArray(Charset.ISO_8859_1))
.response { request, response, result -> log.debug  { "Response: $response" }}

but on server side it looks (read from server logs) that this request was sent with

Content-type application/x-www-form-urlencoded

Logs on client side do not indicate that such 'content-type' element was sent:

Headers: --> http://endpoint/...
"Body : (empty)"
"Headers : (0)"

Am I doing something wrong? Did you spotted such behaviour?

How to do not send Content-type header when using fuel library?

1

There are 1 answers

0
Vinícius Dias Saraiva On

I dont know why Fuel add this default header, but you have two options to not send the header:

  1. add a map

    .header(mapOf("Content-Type" to "application/json"))

  2. Or erase headers before

    request.headers.clear()