Android 使用Kotlin发送带有改装的JSONObject

Android 使用Kotlin发送带有改装的JSONObject,android,kotlin,retrofit2,Android,Kotlin,Retrofit2,我很难找到如何用JSONObject改装@POST interface AuthApi { @Multipart @POST("auth/login") suspend fun userLogin( @Body authResponse: JSONObject? ): Response<AuthResponse> } 直接在@Multipart之后,无效。我想知道如何正确发送我的JSONObject。用户@Part而不是@Body i

我很难找到如何用JSONObject改装@POST

interface AuthApi {
    @Multipart
    @POST("auth/login")
    suspend fun userLogin(
        @Body authResponse: JSONObject?
    ): Response<AuthResponse>
}

直接在
@Multipart
之后,无效。我想知道如何正确发送我的JSONObject。

用户
@Part
而不是
@Body

interface AuthApi {
    @Multipart
    @POST("auth/login")
    suspend fun userLogin(
        @Body authResponse: JSONObject?
    ): Response<AuthResponse>
}

由于您使用的是多部分编码,因此它不会只接收一个身体对象。它接受多个
部分
参数

用户
@Part
而不是
@Body


由于您使用的是多部分编码,因此它不会只接收一个身体对象。它接受多个
Part
parameters

我将@Body行切换为@Part(“authResponse”)authResponse:JSONObject?,但现在我得到了一个错误405。405表示您点击了服务器并确认它在那里,但您对请求使用了不可接受的HTTP方法。仔细检查以确保发送的数据正确。您甚至可能不需要它是一个由多个部分组成的请求。我将@Body行切换为@part(“authResponse”)authResponse:JSONObject?,但现在我得到了一个错误405。405表示您点击了服务器并确认了它在那里,但您对请求使用了不可接受的HTTP方法。仔细检查以确保发送的数据正确。您甚至可能不需要将其作为多部分请求。