Code_Life Code_Life - 1 month ago 13x
Android Question

Retrofit 2.x : Log Header for request and response

I am using retrofit 2.x and i want to log the header and body of request and response .

HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
OkHttpClient client = new OkHttpClient.Builder()
.addNetworkInterceptor(new Interceptor() {
public okhttp3.Response intercept(Chain chain) throws IOException {
Request request = chain.request().newBuilder()
.addHeader("key", "value")
.addHeader("HEADER","HEADER Value")
return chain.proceed(request);


And this how i am doing,my problem is header of request are not being logged in Android Monitor but rest everything is logged .

Gradle Version

compile ('com.squareup.retrofit2:retrofit:2.0.0-beta3') {
// exclude Retrofit’s OkHttp peer-dependency module and define your own module import
exclude module: 'okhttp'
compile 'com.squareup.okhttp3:okhttp:3.0.0-RC1'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta3'
compile ('com.squareup.okhttp3:logging-interceptor:3.0.1'){
exclude module: 'okhttp'

Using RC1 and 3.0.1 due to bug issue reported Bug Link


May it help someone ...

HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();

Add both to see complete logs and add this interceptor at the last (don't know why but its like).