Retrofit: How to send a POST request with constant fields?

后端 未结 4 1326
旧时难觅i
旧时难觅i 2021-02-19 09:29

I want to sent a simple POST request with one actual parameter:

@POST(\"/token\")
@FormUrlEncoded
void extendSession(@Field(\"refresh_token\")final String refres         


        
4条回答
  •  时光取名叫无心
    2021-02-19 10:19

    You may use Java Method Invocation Builder for this.

    @GenerateMethodInvocationBuilder
    public interface ServiceApi {
     @POST("/token")
     @FormUrlEncoded
     void extendSession(
      @Default("theToken") @Field("refresh_token") final String refreshToken,
      @Default("theId") @Field("client_id") final String clientId,
      @Default("theSecret") @Field("client_secret") final String clientSecret,
      @Default("theType") @Field("grant_type") final String grantType);
    }
    

    And then you can invoke the api like:

    ServiceApiExtendedSessionBuilder.extendedSession()
     .withRefreshToken("theRefreshToken")
     .invoke(serviceApi);
    

提交回复
热议问题