改造:如何修复 "only one http method is allowed. found: get and get"?
Retrofit: how fix "only one http method is allowed. found: get and get"?
我有请求的结构。
请求 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);
在第二个GET方法中,第二个参数(@PATH("station"))应该是@PATH("route").
我发现了同样的错误:POST 和 POST,我的问题是我在 URL 中缺少一个路径参数,但我是随请求一起发送的.
我在没有最后一个参数的情况下点击 URL。
http:www.webtest.requestService/customerapp/{context}/{token}/services/{flightLegId}/
实际 URL 应该是:
http:www.webtest.requestService/customerapp/{context}/{token}/services/{flightLegId}/{flightLegExtId}/
这可能是因为微小的错误而发生的,例如您提供的参数不是 {id}。
"GET and GET" 或 "POST and POST" 错误掩盖了根异常。似乎最常见的异常是您在 HTTP 参数方法中的参数与 Path 参数中的参数不匹配。
@GET("/objects/{id}")
中的 {id}
必须匹配 @Path("id")
中的 id
。
我有请求的结构。
请求 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);
在第二个GET方法中,第二个参数(@PATH("station"))应该是@PATH("route").
我发现了同样的错误:POST 和 POST,我的问题是我在 URL 中缺少一个路径参数,但我是随请求一起发送的.
我在没有最后一个参数的情况下点击 URL。
http:www.webtest.requestService/customerapp/{context}/{token}/services/{flightLegId}/
实际 URL 应该是:
http:www.webtest.requestService/customerapp/{context}/{token}/services/{flightLegId}/{flightLegExtId}/
这可能是因为微小的错误而发生的,例如您提供的参数不是 {id}。
"GET and GET" 或 "POST and POST" 错误掩盖了根异常。似乎最常见的异常是您在 HTTP 参数方法中的参数与 Path 参数中的参数不匹配。
@GET("/objects/{id}")
中的 {id}
必须匹配 @Path("id")
中的 id
。