我正在开发一个新的 Android 项目,Retrofit2 对我来说效果很好。但是,在我发送的数据之上,我需要使用两个字符串之一来点击一个 url。
现在它看起来像这样:
@FormUrlEncoded
@POST("token")
Call<AccessResponse> requestAccess(@Field("grant_type") String type, @Field("code") String authCode, @Field("client_id") String ApiKey);
授权类型只是两件事之一,我想将其抽象为静态网址,如下所示:
@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);
有没有办法做到这一点?我 2 天的 google-fu 对我没有用,也没有浏览 API 文档和代码。我只是不想在我的代码的各个地方跟踪正确的字符串。