PhilBlais
PhilBlais

Reputation: 1176

Sending a JSONObject with retrofit using Kotlin

I'm having trouble finding how to do a Retrofit @POST with a JSONObject.

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

When sending I am getting an error:

E/UncaughtException: java.lang.IllegalArgumentException: @Body parameters cannot be used with form or multi-part encoding.

I'm pretty sure I am not sending the JSONObject the right way, but I can't find a good guide to help me with this implementation in Kotlin.

I have tried to add the:

@Headers("Content-Type: application/json; charset=urf-8")

Directly after the @Multipart, to no avail. I would like to know how to correctly send my JSONObject.

Upvotes: 0

Views: 228

Answers (1)

Rafa
Rafa

Reputation: 3339

User @Part instead of @Body

Since your using the Multi Part encoding, it doesn't take in just one Body object. It takes in multiple Part parameters

Upvotes: 2

Related Questions