Retrofit - @Body parameters cannot be used with form or multi-part encoding

前端 未结 5 1359
时光说笑
时光说笑 2020-12-24 05:10

I m trying to make a request in which I want to include a Header , a form-urlencoded field and a json body. My Retrofit interface is as follows

@FormUrlEnc         


        
5条回答
  •  执笔经年
    2020-12-24 05:29

    Adding to Julien's answer, also remove the @Multipart annotation. Here's how I have used it:

    @POST("/app/oauth/token")
    Call getAuthToken(@Body RequestBody body);
    

    And, here is how I have constructed the RequestBody:

    RequestBody requestBody = new MultipartBody.Builder()
                            .setType(MultipartBody.FORM)
                            .addFormDataPart("grant_type", "password")
                            .addFormDataPart("username", username)
                            .addFormDataPart("password", password)
                            .build();
    

提交回复
热议问题