Retrofit 2错误URL查询字符串必须没有替换块

时间:2017-07-08 08:50:07

标签: android retrofit retrofit2

我正在尝试使用Retrofit 2调用遗留API,这是URL "/api/0.3/v3/?endpoint=/admin/customers/6728382/addresses.json",这是接口方法

@GET("/api/0.3/v3/?endpoint=/admin/customers/{customerId}/addresses.json")
Single<GetCustomerAddressesResponse> getUserAddresses(@Path("customerId") String customerId);

但是我收到了这个错误,

  

“网址查询字符串   “endpoint = // admin / customers / {customerId} /addresses.json”必须没有   替换块。对于动态查询参数,请使用@Query。“

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

我认为int必须是String类型。尝试将int更改为{{1}}。

答案 1 :(得分:0)

  

&#34; URL查询字符串&#34; endpoint = // admin / customers / {customerId} /addresses.json"一定不能有替换块。对于动态查询参数,请使用@Query。&#34;

建议您使用@Query代替@Path

Single<GetCustomerAddressesResponse> getUserAddresses(@Query("customerId") String customerId);

您可能希望详细了解@Query注释https://square.github.io/retrofit/2.x/retrofit/index.html?retrofit2/http/Query.html