如何在 Android 中使用 Retrofit 在带有 &
附加参数的 URL 中发出 HTTP GET 请求?
网址:http://api.com?name=remote&class=TV
目前,我正在使用:
@GET("http://api.com?name={name}&class={class}")
Call<CustomType> get(
@Path(value = "name",encoded = false) String name,
@Path(value = "class",encoded = false) String class);
我收到以下错误:
java.lang.IllegalArgumentException: URL query string "name={name}&class={class}"
must not have replace block.
For dynamic query parameters use @Query.
最佳答案
这是一个标准的 GET 请求 url。只需使用@Query
:
@GET("http://api.com")
Call<CustomType> get(
@Query("name") String name,
@Query("class") String classs);
它将访问 url:
http://api.com?name=remote&class=TV
关于android - 使用 Retrofit 在 URL 中获取带有 `&` 附加参数的请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36193494/