URL query string "q={city}" must not have replace block
我不能得到這個工作,我已經嘗試了幾個其他變種,但仍然得到某種形式的例外。如何在Retrofit 2.0+中正確設置註釋和查詢?
public interface WeatherInterface {
@GET("/weather?q={city}")
Call<WeatherModel> getWeather(@Query("city") String city);
}
/////
public interface WeatherInterface {
@GET("/weather")
Call<WeatherModel> getWeather(@Query("q") String city);
}
等。
WeatherActivity.class
Call<WeatherModel> call = weatherInterface.getWeather("""CITYNAME""");
call.enqueue(new Callback<WeatherModel>() {
@Override
public void onResponse(Call<WeatherModel> call, Response<WeatherModel> response) {
if(response.isSuccessful()) {
**///FIRST VARIANT FAILS HERE**
city.setText(response.body().getName());
}
**///SECOND VARIANT FAILES RESPONSE**
else Log.d("No response", "RESPONSE");
}
@Override
public void onFailure(Call<WeatherModel> call, Throwable t) {
Log.d("fail", "fail");
}
});
編輯: Log.d(。call.request()URL()的toString(), 「呼叫請求URL」);
我應該分享我的解決方案太可能了,我只記錄了通話的URL。
是的,我查了資料,但顯然我的API密鑰不見了。該日誌還顯示瞭如何幫助任何人的url調用。 – JoSem