I can\'t find relevant methods in the Retrofit API for logging complete request/response bodies. I was expecting some help in the Profiler (but it only offers meta-data abou
below code is working for both with header and without header to print log request & response. Note: Just comment .addHeader() line if are not using header.
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(interceptor)
//.addInterceptor(REWRITE_CACHE_CONTROL_INTERCEPTOR)
.addNetworkInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Request request = chain.request().newBuilder()
// .addHeader(Constant.Header, authToken)
.build();
return chain.proceed(request);
}
}).build();
final Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constant.baseUrl)
.client(client) // This line is important
.addConverterFactory(GsonConverterFactory.create())
.build();