【发布时间】:2017-05-31 19:33:24
【问题描述】:
URL query string "q={city}" must not have replace block
我无法让它工作,我尝试了其他几种变体,但仍然出现某种形式的异常。
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(), "CALL REQUEST URL");
我也应该分享我的解决方案,我刚刚记录了通话网址。
【问题讨论】: