I want to pass Header and Body dynamically to a Web Api. So, I have implemented as below:
public interface NotificationService {
@POST("user/update/notification")
Call<JsonObject> notification(@Header("Authorization") String authorization, @Body NotificationRequest notificationRequest);
}
And using this as,
showProgressDialog();
NotificationRequest notificationRequest = new NotificationRequest(checked ? ApiConstants.IS_ON : ApiConstants.IS_OFF, getUserId());
NotificationService notificationService = ApiFactory.provideNotificationService();
Call<JsonObject> call = notificationService.notification(getAuthorizationHeader(), notificationRequest);
call.enqueue(new Callback<JsonObject>() {
@Override
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
logDebug(SettingsFragment.class, response.body().toString());
hideProgressDialog();
}
@Override
public void onFailure(Call<JsonObject> call, Throwable t) {
hideProgressDialog();
}
});
But this way, I am not getting null response (response.body()
is null).
Can anyone suggest how to pass Dynamic Header and Body together ?
Note: I went through this tutorial but didn't found the way to pass both.