Square的改造客户端。可变数量的参数

时间:2013-10-24 05:43:40

标签: android rest retrofit

我正在使用Square的Retrofit库。我需要使用可变数量的参数来实现请求。我找到了建议(link),我试试这个:

我改变了

@GET("someURL")
void method(
        @Query("firstParameter") int firstValue,
        @Query("secondParameter") String secondValue,
        Callback<Response> cb
);

@POST("someURL")
void method(
        @Body Map<String, Object> parameters,
        Callback<Response> cb
);

并使用以下内容:

final HashMap<String, Object> param = new HashMap<String, Object>();
param.put("firstParameter", firstValue);
param.put("secondParameter", secondValue);

第一种方式效果很好,但第二种方法不起作用。怎么了?

1 个答案:

答案 0 :(得分:4)

好吧,您正在从GET切换到POST,因此您不是传递查询参数,而是在正文中传递值。

Retrofit目前不支持GET请求中的变量参数。在此GitHub问题中跟踪了添加对此支持的票证:https://github.com/square/retrofit/issues/293