我正在使用2.x改造,我想记录请求和响应的标题和正文。
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();
这就是我正在做的事,我的问题是请求标头未在Android Monitor中记录,但是其余的都记录了。
摇篮版本
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'
}
由于错误问题使用RC1和3.0.1报告了错误链接
可以帮助某人...
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
添加两者以查看完整的日志,并在最后添加此拦截器(不知道为什么,但类似这样)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句