如何正确设置改造参数

joe*_*joe 0 android android-developer-api retrofit2 rx-java2

我正在尝试使用Retrofit 2创建Weather应用程序,现在我很难正确设置呼叫.

这是正在运行的URL:

http://api.openweathermap.org/data/2.5/weather?q=London&APPID=MY_API_KEY
Run Code Online (Sandbox Code Playgroud)

所以,我有我的API密钥和BASE URL是:http://api.openweathermap.org ..这是我的Retrofit服务中的方法:

    @GET("/data/2.5/weather?q={city}/&APPID={api}")
    Observable<WeatherResponse> getWeather(@Path("city") String city, @Path("api") String api);
Run Code Online (Sandbox Code Playgroud)

而我得到的错误是:

java.lang.IllegalArgumentException:URL查询字符串"q = {city} /&APPID = {api}"必须没有替换块.对于动态查询参数,请使用@Query.

所以我试着这样:

@GET("/data/2.5/weather?{city}/&APPID={api}")
Observable<WeatherResponse> getWeather(@Query("city") String city, @Path("api") String api);
Run Code Online (Sandbox Code Playgroud)

我得到同样的错误......任何人都知道这里的交易是什么,我的网址有什么问题?

Tom*_*ura 5

这样做:

@GET("/data/2.5/weather")
Observable<WeatherResponse> getWeather(@Query("q") String city, @Query("APPID") String api);
Run Code Online (Sandbox Code Playgroud)

无需在Retrofit中手动输入参数值 - 您只需告诉它什么是参数名称