1

I have to call an api using retrofit 2 in android. but with no values. When I does that, it shows that there must be at least 1 @field. Below is the code I am using.

public interface gitAPI {
    @FormUrlEncoded
    @POST("/MembersWS.svc/GetMemberAvailability/MBR0011581")
    Call<Questions[]> loadQuestions();
}






Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://192.168.1.99:82")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    // prepare call in Retrofit 2.0
    gitAPI stackOverflowAPI = retrofit.create(gitAPI.class);

    Call<Questions[]> call = stackOverflowAPI.loadQuestions();
    call.execute();
Sachin Malik
  • 129
  • 9

1 Answers1

1

Declare body value in your interface with next:

@Body RequestBody body and wrap String JSON object:

RequestBody body = RequestBody.create(MediaType.parse("application/json"), (new JsonObject()).toString());
kkost
  • 3,640
  • 5
  • 41
  • 72
  • 1
    @SreekanthKarumanaghat sry, that was a long time ago, I don't work with Java currently. Probably link to my another question with the same answer will be helpful for you https://stackoverflow.com/questions/35880907/retrofit-unable-to-create-body-converter-for-class/57819497#57819497 – kkost Jan 16 '20 at 13:05