Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit multiple POST params

I'm trying to submit a call to a server that requires 2 sets of information, this is my interface:

@POST("/venues/get-by-location")
void getByLocation(@Body Coordinates coordinates,
                   @Body MaxDistanceBody maxDistance,
                   Callback<MyCallback> callback);

but I receive this error: " Multiple @Body method annotations found."

How can I send multiple objects in one Post request? Thanks!

like image 279
user1064249 Avatar asked Aug 11 '14 21:08

user1064249


2 Answers

If you just want to send them as a regular body, you can create a helper class that contains all your values. Something like:

KOTLIN:

class VenuesRequestBody(coordinates: Coordinates, maxDistance: MaxDistance)

-

@POST("/venues/get-by-location")
fun getByLocation(@Body loginRequest: LoginRequest): Call<MyCallback>

JAVA (written without testing):

public class VenuesRequestBody {
    Coordinates coordinates;
    MaxDistance maxDistance;

    VenuesRequestBody(Coordinates coordinates, MaxDistance maxDistance) {
        this.coordinates = coordinates;
        this.maxDistance = maxDistance;
    }
}

-

@POST("/venues/get-by-location")
void getByLocation(@Body VenuesRequestBody requestBody,
                   Callback<MyCallback> callback);
like image 196
Otziii Avatar answered Nov 15 '22 07:11

Otziii


Maybe this can help:

@Multipart
@POST("/venues/get-by-location")
void getByLocation(@Part("coordinates") Coordinates coordinates,
                   @Part("maxDistanceBody") MaxDistanceBody maxDistance,
                   Callback callback);
like image 28
code4fun Avatar answered Nov 15 '22 07:11

code4fun