I am using the following libraries for retrofit.
'com.squareup.retrofit2:retrofit:2.5.0'
'com.squareup.okhttp:okhttp:2.7.5'
'com.squareup.retrofit2:converter-gson:2.5.0'
'com.squareup.okhttp3:logging-interceptor:3.10.0'
How can I get the raw response in onResponse callback? I already searched for it and got a lots of solutions which doesn't help now. I tried response.raw().body.string()
and response.body().source().toString()
which throws can not read body from a converted body. I also tried response.body().string()
but in this case .string()
is unresolved. I can log the response using interceptor but I need that response in my onResponse()
callback, not just printing in logcat.
My Retrofit Client:
public static ApiService getClient(Context context) {
if (retrofit == null) {
if (BuildConfig.FLAVOR.equalsIgnoreCase("dev")){
retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BASE_URL)
.client(okHttpClient)
.build();
}else {
retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BASE_URL)
.client(SelfSigningClientBuilder.createClient(context))
.build();
}
}
return retrofit.create(ApiService.class);
}
My Retyrofit Interface:
@retrofit2.http.POST("weekly_driver_earning_report/")
@retrofit2.http.FormUrlEncoded
Call<List<DailyEarnings>> getDriverWeeklyEarnings(@retrofit2.http.Field("access_token") String access_token, @retrofit2.http.Field("start_date") String start_date, @retrofit2.http.Field("end_date") String end_date);
>` into `Call` to get the whole http response in the callback.
– denvercoder9 Sep 22 '19 at 05:24