【问题标题】:IllegalArgumentException in Retrofit / must not have replace block / Dynamic Url / Retrofit 2Retrofit 中的 IllegalArgumentException / 不能有替换块 / Dynamic Url / Retrofit 2
【发布时间】:2019-07-15 18:56:18
【问题描述】:
我有以下代码:
interface WeatherApi {
@GET("/v1/forecast.json?key=**********&q={state}&days=4")
fun getWeather(@Query("state") state: String): Single<Weather>
}
根据官方文档,我必须使用@Query,并且我正在使用它,但是我收到以下错误:
URL 查询字符串“key=************&q={state}&days=4”不能有替换块。对于动态查询参数,请使用@Query。
【问题讨论】:
标签:
android
rx-java
retrofit2
【解决方案1】:
您必须使用此代码
interface WeatherApi {
@GET("/v1/forecast.json")
fun getWeather(@Query("key") key: String,@Query("q") state: String,@Query("days") days: Int): Single<Weather>
}