改造:如何修复"只允许一种http方法。发现:得到并得到"?

时间:2015-04-10 08:04:40

标签: android retrofit

我有请求的结构 请求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);

4 个答案:

答案 0 :(得分:11)

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

答案 1 :(得分:1)

我发现了同样的错误:POST和POST,我的问题是我错过了我的网址中的路径参数,但是我一直在发送请求。

我正在点击没有最后一个参数的网址。

  

HTTP:www.webtest.requestService / customerapp / {上下文} / {令牌} /服务/ {flightLegId} /

实际网址应为:

  

HTTP:www.webtest.requestService / customerapp / {上下文} / {令牌} /服务/ {flightLegId} / {flightLegExtId} /

答案 2 :(得分:1)

错误&#34; GET和GET&#34;或者&#34; POST和POST&#34;错误掩盖了根异常。似乎最常见的例外是HTTP参数方法中的参数与Path参数中的参数不匹配。

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

答案 3 :(得分:0)

这种情况可能会发生,因为如果您提供的参数不是{id},那么就会发生微小的错误。