skip to Main Content

I designed an API that sends data in parameters, however retrofit prevents us from sending data in parameters through a post request. Is there a way to send data in parameters through a post request with retrofit?

2

Answers


  1. Reference:
    https://square.github.io/retrofit/2.x/retrofit/retrofit2/http/Field.html

    @FormUrlEncoded
    @POST("/")
    Call<ResponseBody> example(
        @Field("name") String name,
        @Field("occupation") String occupation);
    
    Login or Signup to reply.
  2. You can make a Pojo/Data class for your desired parameters and Then you can make an object by passing all your parameter. Then you can send data through post by using @Body tag like:

     @POST("/")
     Call<ResponseType> send(@Body Data data)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search