Skip to content Skip to sidebar Skip to footer

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

Solution 1:

Maybe this can help:

@Multipart@POST("/venues/get-by-location")
void getByLocation(@Part("coordinates") Coordinates coordinates,
                   @Part("maxDistanceBody") MaxDistanceBody maxDistance,
                   Callback callback);

Solution 2:

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:

classVenuesRequestBody(coordinates: Coordinates, maxDistance: MaxDistance)

-

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

JAVA (written without testing):

publicclassVenuesRequestBody{
    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);

Solution 3:

Try this one:

@Multipart@POST("/merchantservice/saveservice")
void SaveServiceApi(
         @Body MultipartTypedOutput file,
         @Body MultipartTypedOutput Videofile,
         @Query("title") String title,
         Callback<ResponseSaveService> callback);

Post a Comment for "Retrofit Multiple Post Params"