使用Fuel向身体发送GET请求

时间:2018-12-24 02:07:25

标签: android json kotlin

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

有其他选择吗?

我遵循你的职责,

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”。有解决方案吗?

2 个答案:

答案 0 :(得分:0)

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

  

.upload请求是application / form-multipart,这总是需要   此刻的DataPart

答案 1 :(得分:0)

Fuel lib开发人员回答我,它将添加到2.0.0版本中

github answer from Fuel dev

相关问题