Ich benutze Retrofit-Bibliothek und ich möchte Wetterbericht von OpenWeatherAPI bekommen.So fügen Sie Variable zu verknüpfen
Ich habe das.
Basis-URL: 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);
Aber ich habe schlechte url (ich weiß nicht, wie es zu reparieren) -
Antwort {protocol = http/1.1, Code = 502 Nachricht = Bad Gateway, url = http://api.openweathermap.org/data/2.5/weather?q=&units=&appid=111111111111111111111111&city=&units=metric}
Ja, aber wie diese Werte an URL übergeben? – Stepan
mit Nur-Text können Sie tun "? Q = London" oder Sie können es mit Variablen und String-Verkettung so tun: String place = "London"; "? q =" + place + "& city =" + .... – MichaelStoddart
und ist das möglich? '@GET (" weather? Q = {city} & units = {units} & appid = "+ API_KEY) Aufruf getWeatherCity (@Path (" city ") String city, @Path (" units ") String units);' es gibt mir einen Fehler –
Stepan