Reputation: 129
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
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