问题
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