我正在开发一个新的Android项目,而Retrofit2对我来说效果很好.但是,我需要在我发送的数据之上使用两个字符串中的一个来命中一个网址.
现在它看起来像这样:
@FormUrlEncoded
@POST("token")
Call<AccessResponse> requestAccess(@Field("grant_type") String type, @Field("code") String authCode, @Field("client_id") String ApiKey);
Run Code Online (Sandbox Code Playgroud)
授权类型只是两件事之一,我想把它抽象成静态网址,如下所示:
@FormUrlEncoded
@POST("token")
@Field("grant_type","type1")
Call<AccessResponse> requestAccess( @Field("code") String authCode, @Field("client_id") String ApiKey);
@FormUrlEncoded
@POST("token")
@Field("grant_type","type2")
Call<AccessResponse> refreshAccess( @Field("code") String authCode, @Field("client_id") String ApiKey);
Run Code Online (Sandbox Code Playgroud)
有没有办法实现这个目标?我2天的google-fu没有为我工作,也没有浏览API文档和代码.我只是不想在我的代码中的各个地方跟踪正确的字符串.
结果答案是“你现在不能”。
Github 上有一个关于功能请求的未解决问题
还有一种替代方法,即具有此 SO post中提到的方法示例的 FieldMap 对象,但它并不完全是我想要的,并且对于一个字段来说太过分了。
| 归档时间: |
|
| 查看次数: |
508 次 |
| 最近记录: |