retrofit2 - Retrofit2 传递列表作为 URL 参数
问题描述
我正在尝试使用字符串列表发出 GET 请求。
像这样改造表示列表;
/endpoint?GTIN=111>IN=222
但是服务器(Springboot)只给出最后一个结果。
它适用于这个
/endpoint?GTIN=111,222
有没有办法在改造中做后者?
解决方案
您可以尝试使用 Retrofit 的@Url
注释来生成所需的 URL。
在您的服务接口文件中更改您的 API 方法,
public interface YourServiceInterface {
@GET() // DO NOT pass any arguments here
Call<YourResponseObject> foo(@Url String url); // use @Url annotation here
}
在您的活动或片段中。
String url = BASE_URL + "/endpoint?GTIN=111,222"; // https://example.com/endpoint?GTIN=111,222
YourServiceInterface api = ....;
Call<YourResponseObject> call = api.foo(url);
call.enqueue(/* implementation */);
推荐阅读
- python - 使用 urllib 打开带重音符号的 url
- javascript - Javascript - 将事件侦听器添加到多个元素
- c# - 是否可以让任何数据流块类型作为单个输入的结果发送多个中间结果?
- node.js - 保护 AWS S3 下载链接
- javascript - 在为动态内容加载文档后尝试手动调用 MathJax 时出现“ReferenceError:MathJax 未定义”
- c - 如何找到大数的二进制表示?
- java - LinkOption.NOFOLLOW_LINKS 的含义是什么以及何时使用它?
- javascript - 试图切换 dd 元素的可见性
- javascript - 类中的 PHP 函数返回空值
- html - alt="" 在技术上不可行的空 alt 属性的最佳实践