Retrofit: how fix “only one http method is allowed. found: get and get”?

◇◆丶佛笑我妖孽 提交于 2021-01-27 05:23:28

问题


I have that structure for request.
Request getTransportByStation work perfectly. But I get exception java.lang.IllegalArgumentException: TransportWebService.getTransportByRoute: Only one HTTP method is allowed. Found: GET and GET. I found solution only for POST and 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: Retrofit version 1.9.0
Init service like this

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

回答1:


In the second GET method, the second argument (@PATH("station")) should be @PATH("route").




回答2:


I had the same error found: POST and POST, my issue was that I was missing a path parameter in my URL but I was sending it along with the request.

I was hitting the URL without last parameter.

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

Actual URL was should be:

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




回答3:


The error the "GET and GET" or "POST and POST" error is masking the root exception. It seems the most common exception is that your argument in the HTTP argument method does not match the argument in your Path parameter.

The {id} in @GET("/objects/{id}") must match id in @Path("id").




回答4:


This may happen because of tiny mistake like if you are giving parameter like instead of {id}.



来源:https://stackoverflow.com/questions/29556313/retrofit-how-fix-only-one-http-method-is-allowed-found-get-and-get

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!