我正在使用翻新庫,我想從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