【问题标题】:Retorfit query param taking & and ? together改造查询参数采用 & 和 ?一起
【发布时间】:2021-12-20 00:30:00
【问题描述】:

我必须执行以下 API 调用

网址https://devipapi.octavehi.com/api/state/select-list-items?countryId=236

我创建的改造函数是

@GET("country/state/select-list-items?")
suspend fun fetchStates(@Query("countryId") id: Int): Response<List<ServerState>>

但是我从改造中返回了这个 URL

https://devipapi.octavehi.com/api/country/state/select-list-items?&countryId=236

安培 (&) 与 ? 一起附加

如何解决这个问题?

【问题讨论】:

  • 删除?。它假定一个没有 查询字符串 的 URL,它是 ?...=...&amp;...=...&amp;...=... 形式的参数列表。由于 URL 已包含问号,因此在参数前需要一个 & 号。

标签: android retrofit retrofit2


【解决方案1】:

删除“?”来自@GET

@GET("country/state/select-list-items")
suspend fun fetchStates(@Query("countryId") id: Int): Response<List<ServerState>>

【讨论】:

    【解决方案2】:

    解决者

    @GET("city/select-list-items")
    suspend fun fetchCities(@Query(value="stateId", encoded = true) id: Int): Response<List<ServerCity>>
    

    【讨论】:

      猜你喜欢
      • 2019-05-15
      • 2018-02-11
      • 2016-08-12
      • 2020-08-07
      • 1970-01-01
      • 1970-01-01
      • 2021-06-18
      • 1970-01-01
      相关资源
      最近更新 更多