android - Retrofit 中这个 URL 的接口是什么
问题描述
在Get
方法中:
http://xyz.erprnd.com/api/v1/customers/get?yearmonth=201807
我的设计界面:
@Headers({ "Content-Type: application/json;charset=UTF-8"})
@GET("customers/{get}/{yearmonthValue}")
Call<CustResponse> CustomerData(@HeaderMap Map<String, String> headers,
@Path("get") String get,
@Query("yearmonth") String yearmonth,
@Path("yearmonthValue") String yearmonthValue,
@Header("Authorization") String authHeader);
我可以改变什么来使它正常工作?
解决方案
首先,在构建 Retrofit 时,仔细检查您是否将“ http://xyz.erprnd.com/api/v1 ”作为您的baseUrl传递。
然后,根据您发布的 URL,界面应如下所示:
@Headers({ "Content-Type: application/json;charset=UTF-8"})
@GET("customers/get")
Call<CustResponse> CustomerData(@HeaderMap Map<String, String> headers,
@Header("Authorization") String authHeader,
@Query("yearmonth") String yearmonth);
当你定义查询参数时,你只需要添加注解@Query("param_name") 然后传入的变量的值就是transform intro: param_name=variable_value
另外,我删除了您的 @Path("get") 参数,因为 URL 的那部分似乎永远/get
不会改变。不幸的是,我无法测试它,因为我没有对您的 API 的授权。
推荐阅读
- asp.net-core - 如何在asp.net核心的剃刀视图中隐藏一些文本字段
- r - Knitr 未加载/未找到?
- android - 谷歌地图适用于 Android Release APK 但不适用于 AAB
- android - 将数据传递给 Kotlin 中的服务
- android - 保存地理定位
- java - 必须扩展类与其扩展的类具有相同的访问级别
- python - 将变量/约束添加到 Gurobi 持久性时的 AttributeErrors
- python - PIL(Pillow)getsize_multiline()在while循环中进入无限循环?
- javascript - 在 TestRail 中集成 Cypress
- angular - Angular 应用程序不再构建。未找到 build-long.md