Retrofit POST Request with body parameters android

后端 未结 3 1332
Happy的楠姐
Happy的楠姐 2021-01-28 05:25

I need to execute post request with retrofit but i have a problem which i can\'t understand very well. Before trying with code i tested api call with Postman an

3条回答
  •  太阳男子
    2021-01-28 06:07

    You are using a Gson converter factory. It might be easier to create a single object that represents your body, and use that instead of all individual parameters. That way, you should be able to simple follow along with the examples on the Retrofit website.enter link description here There are also many site that let you generate your Plain Old Java Objects for you, like this one:

    E.g. your Api call:

    @POST("api/android-feedback")
    Call sendFeedback(@Body FeedbackBody feedback);    
    

    And your FeedbackBody class:

    public class FeedbackBody{
        private final String email;
        private final String feedback;
    
        public FeedbackBody(String email, String feedback){
            this.email = email;
            this.feedback = feedback;
        }
    }
    

提交回复
热议问题