改进多个POST参数

时间:2014-08-11 21:02:15

标签: android retrofit

我尝试向需要2组信息的服务器提交呼叫,这是我的界面:

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

但我收到此错误:&#34;找到了多个@Body方法注释。&#34;

如何在一个Post请求中发送多个对象?谢谢!

3 个答案:

答案 0 :(得分:26)

也许这会有所帮助:

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

答案 1 :(得分:0)

如果只想将它们作为常规正文发送,则可以创建一个包含所有值的帮助器类。 像这样:

科特琳:

class VenuesRequestBody(coordinates: Coordinates, maxDistance: MaxDistance)

-

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

JAVA(未经测试编写):

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

答案 2 :(得分:-3)

试试这个:

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