Sachin Malik
Sachin Malik

Reputation: 129

How to send a retrofit 2 post call with no parameters

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();

Upvotes: 1

Views: 1648

Answers (1)

kkost
kkost

Reputation: 3760

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());

Upvotes: 1

Related Questions