2

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

我改变

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

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

4

1 回答 1

4

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

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

于 2013-10-30T16:35:03.533 回答