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!
If you just want to send them as a regular body, you can create a helper class that contains all your values. Something like:
class VenuesRequestBody(coordinates: Coordinates, maxDistance: MaxDistance)
-
@POST("/venues/get-by-location")
fun getByLocation(@Body loginRequest: LoginRequest): Call<MyCallback>
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);
Maybe this can help:
@Multipart
@POST("/venues/get-by-location")
void getByLocation(@Part("coordinates") Coordinates coordinates,
@Part("maxDistanceBody") MaxDistanceBody maxDistance,
Callback callback);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With