android - 使用 Retrofit 在 URL 中获取带有 `&` 附加参数的请求

标签 android exception annotations httprequest retrofit2

如何在 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/

相关文章:

r - 一种测试一组外显子/内含子/utr 基因组位置的方法?

java - 使用 Jquery 和 servlet 检索图像会产生 HTTP Status 500 错误

android - 如何通过 AsyncTask 正确使用 Intent 和 Uri 数据

android - Android 上触摸释放时触发 OnPointerExit() 的解决方案?

java - Android - forName() 方法 ClassNotFoundException

java - 扫描仪无法正常工作

wpf - VS 2010 : Exceptions when XAML file of project that includes System. Windows.Interactivity 已打开

java - 将 @Generated 注释添加到 JAXB 生成的类

Java - 使用 javadoc 和方法注释的约定?

android - 使用 XmlResourceParser 解析内部存储中的 xml 文件