【问题标题】:Retrofit: how fix "only one http method is allowed. found: get and get"?改造:如何修复“只允许一种 http 方法。找到:get 和 get”?
【发布时间】:2015-04-10 08:04:39
【问题描述】:

我有请求的结构。
请求 getTransportByStation 完美运行。 但我得到异常java.lang.IllegalArgumentException: TransportWebService.getTransportByRoute: Only one HTTP method is allowed. Found: GET and GET. 我找到了仅适用于 POST 和 POST 的解决方案。

interface TransportWebService {
    @GET(QUERY_CATEGORY_TRANSPORT + "GetTransportByNextStation/{station}")
    Observable<ResponseRouteList> getTransportByStation(
            @Path("city") String city,
            @Path("station") String station,
            @Query("count") int count,
            @Query("userid") String userId
    );

    @GET(QUERY_CATEGORY_TRANSPORT + "GetTransportByRoute/{route}")
    Observable<ResponseRouteList> getTransportByRoute(
            @Path("city") String city,
            @Path("station") String route,
            @Query("count") int count,
            @Query("userid") String userId
    );

    @GET(QUERY_CATEGORY_TRANSPORT + "Time")
    Observable<Integer> getTime(
            @Path("city") String city
    );
}

UPD:改造版本 1.9.0
像这样初始化服务

private static final TransportWebService SERVICE = Common.getRestAdapter()
            .setConverter(new GsonConverter(new Gson())
            .build()
            .create(TransportWebService.class);

【问题讨论】:

    标签: android retrofit


    【解决方案1】:

    在第二个 GET 方法中,第二个参数 (@PATH("station")) 应该是 @PATH("route")。

    【讨论】:

      【解决方案2】:

      我发现了同样的错误:POST 和 POST,我的问题是我的 URL 中缺少路径参数,但我将它与请求一起发送。

      我点击了没有最后一个参数的 URL。

      http:www.webtest.requestService/customerapp/{context}/{token}/services/{flightLegId}/

      实际网址应该是:

      http:www.webtest.requestService/customerapp/{context}/{token}/services/{flightLegId}/{flightLegExtId}/

      【讨论】:

        【解决方案3】:

        这可能是因为一个小错误,比如你给参数 like 而不是 {id}。

        【讨论】:

          【解决方案4】:

          “GET 和 GET”或“POST 和 POST”错误掩盖了根异常。似乎最常见的例外是您在 HTTP 参数方法中的参数与您的 Path 参数中的参数不匹配。

          @GET("/objects/{id}") 中的{id} 必须与@Path("id") 中的id 匹配。

          【讨论】:

            猜你喜欢
            • 2020-06-26
            • 1970-01-01
            • 2013-11-10
            • 2018-11-12
            • 2019-11-30
            • 2020-07-19
            • 2019-06-27
            • 2021-07-01
            • 1970-01-01
            相关资源
            最近更新 更多