android - Retrofit 2.x : Log Header for request and response -
i using retrofit 2.x , want log header , body of request , response .
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("key", "value") .addheader("header","header value") .build(); return chain.proceed(request); } }).build();
and how doing,my problem header of request not being logged in android monitor rest logged .
gradle version
compile ('com.squareup.retrofit2:retrofit:2.0.0-beta3') { // exclude retrofit’s okhttp peer-dependency module , define 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 , 3.0.1 due bug issue reported bug link
may ...
httplogginginterceptor interceptor = new httplogginginterceptor(); interceptor.setlevel(httplogginginterceptor.level.header); interceptor.setlevel(httplogginginterceptor.level.body);
add both see complete logs , add interceptor @ last (don't know why like).
Comments
Post a Comment