我已经尝试了两种类型的值传递给Android Retrofit库中的URL,方法1执行时没有任何错误,但方法2抛出错误。在Android Retrofit库中传递值到URL的差异
我发送参数值通过查询键名与注释参数的值在方法1和可变取代的API端点在方法2
错误由方法2抛出:
java.lang.IllegalArgumentException: URL query string "appid={apikey}&lat={lat}&lon={lon}&units={units}" must not have replace block. For dynamic query parameters use @Query.
我网址:数据/ 2.5 /天气LAT = 77.603287 & LON = 12.97623 &的appid = f5138 &单位=度量
方法1:(执行的孔)
@GET("data/2.5/weather")
Call<Weather> getWeatherReport(@Query("lat") String lat,
@Query("lon") String lng,
@Query("appid") String appid,
@Query("units") String units);
方法2:(错误)
@GET("data/2.5/weather?appid={apikey}&lat={lat}&lon={lon}&units={units}")
Call<Weather> getWeatherReport1(@Query("apikey") String apikey,
@Query("lat") String lat,
@Query("lon") String lng,
@Query("units") String units);
我试图@Path以及在第二方法。
我的问题是 1.两种方法之间有什么区别? 2.为什么第二种方法不起作用?
理论上路径替换查询应该这样做。第一个为你构造一个查询字符串,第二个是你手动创建的。 –