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