Sachin Malik Sachin Malik - 1 year ago 110
Android Question

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 {
Call<Questions[]> loadQuestions();

Retrofit retrofit = new Retrofit.Builder()
// prepare call in Retrofit 2.0
gitAPI stackOverflowAPI = retrofit.create(gitAPI.class);

Call<Questions[]> call = stackOverflowAPI.loadQuestions();

Answer Source

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());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download