如何正确设置改造参数

时间:2017-01-07 14:25:49

标签: android retrofit2 android-developer-api rx-java2

我正在尝试使用Retrofit 2创建天气应用,现在我很难正确设置呼叫。

这是正在运行的网址:

http://api.openweathermap.org/data/2.5/weather?q=London&APPID=MY_API_KEY

所以,我已经获得了我的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);

我得到的错误是:

java.lang.IllegalArgumentException:URL查询字符串&#34; q = {city} /&amp; APPID = {api}&#34;一定不能有替换块。对于动态查询参数,请使用@Query。

所以我试过这样:

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

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

1 个答案:

答案 0 :(得分:5)

这样做:

physical memory

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

相关问题