2017-05-31 33 views
1
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。

回答

0

我忘了在url中添加我的API KEY。我可耻地撤回我的问题。

0

U可以使用此示例采取例如:

public interface GitHubClient { 
     @GET("https://stackoverflow.com/users/{user}/repos") 
     Call<List<GitHubRepo>> reposForUser(
      @Path("user") String user 
     ); 
    } 

更多的样品只需访问该website

+0

是的,我查了资料,但显然我的API密钥不见了。该日志还显示了如何帮助任何人的url调用。 – JoSem

相关问题