Retrofit multiple POST params

纵然是瞬间 提交于 2020-01-01 08:43:25

问题


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!


回答1:


Maybe this can help:

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



回答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:

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



回答3:


Try this one:

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


来源:https://stackoverflow.com/questions/25252359/retrofit-multiple-post-params

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!