【问题标题】:Send a GET request with a body using Fuel使用 Fuel 发送带有 body 的 GET 请求
【发布时间】:2018-12-24 02:07:25
【问题描述】:

我需要发送一个带有 GET 请求的正文,但得到了:"Exception : lateinit property sourceCallback has not been initialized". 我在 kotlin 1.3.10 中使用 Fuel 和 Android Studio

有其他选择吗?

我遵循你的职责,

private fun getReq (json : JSONObject) {

    thread {
        FuelManager.instance.basePath = "https://blih.epitech.eu"
        Fuel.upload("/repositories", Method.GET)
            .body(json.toString().toByteArray())
            .header("Content-Type" to "application/json")
            .response { request, response, result ->
                val (bytes, error) = result
                if (bytes != null) {
                    println("[response bytes] ${String(bytes)}")
                }
                println(error)
            }
    }
    Thread.sleep(1000)
}

更新:

我添加了.source { _, _ -> File.createTempFile("temp", ".tmp")},并且 sourceCallback 不再有问题,但现在得到“异常:方法不支持请求正文:GET”。有什么解决办法吗?

【问题讨论】:

    标签: android json kotlin


    【解决方案1】:

    Fuel lib 的开发者回答我,它将添加到 2.0.0 版中

    github answer from Fuel dev

    【讨论】:

      【解决方案2】:

      根据this github issue,使用upload时需要.dataParts

      .upload 请求是 application/form-multipart,它总是需要 目前的数据部分

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-03-16
        • 1970-01-01
        • 2018-01-25
        • 1970-01-01
        • 2011-09-20
        • 1970-01-01
        相关资源
        最近更新 更多