1
동적으로 헤더 및 본문을 웹 API에 전달하려고합니다. 그래서, 다음과 같이 구현 :retrofit 2 : 본문과 함께 동적 헤더 전달
public interface NotificationService {
@POST("user/update/notification")
Call<JsonObject> notification(@Header("Authorization") String authorization, @Body NotificationRequest notificationRequest);
}
등이 사용
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();
}
});
그러나이 방법은, 내가 널 응답 (response.body()
가 null) 받고 있지 않다.
누구나 동적 머리글과 본문을 함께 전달하는 방법을 제안 할 수 있습니까?
참고 :this 튜토리얼을 밟았지만 두 가지 방법 모두를 통과하지 못했습니다.
이 anwser http://stackoverflow.com/questions/29884967/how-to-dynamically-set-headers-in-retrofit을 확인하십시오 :
그냥 같은 뭔가 조건이있는 경우에 선 아래 포장 -android/29885004 # 29885004 –
@RobertEstivill 답변에 표시된 것처럼 이미 헤더를 동적으로 전달하고 있습니다. –