你好,我正在尝试使用ktor进行多格式请求,但我得到了上面的错误。我如何serilize MultiPartBody?
val body = MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("choice","John Wick")
.addFormDataPart("image",path,
File(path).asRequestBody("application/octet-stream".toMediaType()))
.build()
val httpResponse = client.post {
url("https://example.com")
setBody(body)
header("Content-Type","application/json")
header("Authorization", "Bearer key")
}
字符串
1条答案
按热度按时间fzsnzjdm1#
Ktor无法直接发送
okhttp3.MultipartBody
类的对象。请改用MultiPartFormDataContent
类:字符串