简体   繁体   中英

Kotlin Fuel library - cannot send request without default header

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?

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM