如何在retrofit2中动态更改url的结尾

时间:2016-08-18 12:43:14

标签: java android post path retrofit2

我试图在POST请求中动态更改URL的结尾。

@POST("/api/registrations/{key}")
Call<RegistrationResponse> confirmRegister(
   @Body RegisterParam registerParam, @Path("key") String key);

 D/OkHttp: --> POST http://base_url/api/registrations/ http/1.1
08-18 18:44:43.138 20510-20672/ D/OkHttp: Content-Type: application/json; charset=UTF-8
08-18 18:44:43.138 20510-20672/ D/OkHttp: Content-Length: 72
 D/OkHttp: <-- 404 Not Found base_url/registrations (449ms)
08-18 18:44:43.588 20510-20672/ D/OkHttp: Date: Thu, 18 Aug 2016 12:44:44 GMT

我会得到这样的结果:

POST base_url/api/registrations/ajksdiuqwdqhiwuqdhiquhd

1 个答案:

答案 0 :(得分:0)

这是@POST请求但@PATCH请求。下面的代码按预期工作。抱歉导致误入歧途。谢谢大家。

@PATCH("/api/registrations/{key}")
Call<RegistrationResponse> confirmRegister(
@Body RegisterParam registerParam, @Path("key") String key);