【问题标题】:Kotlin Fuel library - cannot send request without default headerKotlin Fuel 库 - 无法在没有默认标头的情况下发送请求
【发布时间】:2020-02-29 17:48:18
【问题描述】:

Fuel 库 - 无法发送没有默认标头的请求。

我正在尝试发送没有 Content-Type 标头的示例性请求:

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" }}

但在服务器端,它看起来(从服务器日志中读取)该请求是与发送的

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

客户端的日志并不表明发送了这样的“内容类型”元素:

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

我做错了吗?你有没有发现这样的行为?

使用fuel库时如何不发送Content-type header?

【问题讨论】:

    标签: kotlin http-headers httprequest fuel


    【解决方案1】:

    我不知道为什么 Fuel 添加此默认标头,但您有两个选项可以不发送标头:

    1. 添加地图

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

    2. 或删除之前的标题

      request.headers.clear()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-06
      • 2018-08-04
      • 2017-09-15
      • 2010-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多