【问题标题】:Square's Retrofit Client. Variable number of parameters [closed]Square 的改造客户端。可变数量的参数[关闭]
【发布时间】:2013-11-02 16:24:54
【问题描述】:

我正在使用 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);

第一种方法很好用,但第二种方法不行。怎么了?

【问题讨论】:

标签: android rest retrofit


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2015-10-06
    • 2016-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多