Sending JSON in POST request with Retrofit2

后端 未结 4 1482
既然无缘
既然无缘 2020-12-03 11:24

I\'m using Retrofit to integrate my Web services and I do not understand how to send a JSON object to the server using a POST request. I\'m currently stuck, here is my code:

4条回答
  •  旧巷少年郎
    2020-12-03 12:01

    i think you should now create a service generator class and after that you should use Call to call your service

    PostInterface postInterface = ServiceGenerator.createService(PostInterface.class);
    Call responseCall =
                postInterface.getStringScalar(requestBody);
    

    then you can use this for synchronous request and get the body of response:

    responseCall.execute().body();
    

    and for asynchronous :

    responseCall.enqueue(Callback);
    

    refer to link provided below for complete walkthrough and how to create ServiceGenerator :

    https://futurestud.io/tutorials/retrofit-getting-started-and-android-client

提交回复
热议问题