我正在使用翻新库,我想从OpenWeatherAPI获取天气预报。如何添加变量链接
我有这个。
基地网址:http://api.openweathermap.org/data/2.5/
@GET("weather?q=&units=&appid=" + API_KEY)
Call<WeatherAPI> getWeatherCity(@Query("city") String city, @Query("units") String units);
,但我得到不好的网址(我不知道如何修复它) -
响应{协议= HTTP/1.1,代码= 502,消息= Bad Gateway, url = http://api.openweathermap.org/data/2.5/weather?q=&units=&appid=111111111111111111111111&city=&units=metric}
是的,但如何将该值传递给url? – Stepan
用纯文本你可以做“?q = london”,或者你可以用变量和字符串连接来做到这一点:String place =“london”; “?q =”+ place +“&city =”+ .... – MichaelStoddart
这是可能的吗? '@GET(“weather?q = {city}&units = {units}&appid =”+ API_KEY) 调用 getWeatherCity(@Path(“city”)String city,@Path(“units”)String units);'它给了我一个错误 –
Stepan