使用 Kotlin 发送改造后的 JSONObject
Sending a JSONObject with retrofit using Kotlin
我无法找到如何使用 JSONObject 进行改造@POST。
interface AuthApi {
@Multipart
@POST("auth/login")
suspend fun userLogin(
@Body authResponse: JSONObject?
): Response<AuthResponse>
}
发送时出现错误:
E/UncaughtException: java.lang.IllegalArgumentException: @Body
parameters cannot be used with form or multi-part encoding.
我很确定我没有以正确的方式发送 JSONObject,但是我找不到好的指南来帮助我在 Kotlin 中实现这个。
我尝试添加:
@Headers("Content-Type: application/json; charset=urf-8")
直接后@Multipart
,无果。我想知道如何正确发送我的 JSONObject。
用户 @Part
而不是 @Body
由于您使用的是多部分编码,它不会只接收一个 Body 对象。它接受多个 Part
参数
我无法找到如何使用 JSONObject 进行改造@POST。
interface AuthApi {
@Multipart
@POST("auth/login")
suspend fun userLogin(
@Body authResponse: JSONObject?
): Response<AuthResponse>
}
发送时出现错误:
E/UncaughtException: java.lang.IllegalArgumentException: @Body parameters cannot be used with form or multi-part encoding.
我很确定我没有以正确的方式发送 JSONObject,但是我找不到好的指南来帮助我在 Kotlin 中实现这个。
我尝试添加:
@Headers("Content-Type: application/json; charset=urf-8")
直接后@Multipart
,无果。我想知道如何正确发送我的 JSONObject。
用户 @Part
而不是 @Body
由于您使用的是多部分编码,它不会只接收一个 Body 对象。它接受多个 Part
参数