我想在不使用okHttp库的情况下记录retrofit2请求的完整请求(URL,请求参数,正文)。怎么做到呢
最佳答案
您必须添加logging-interceptor:
编译'com.squareup.okhttp3:logging-interceptor:3.4.1'
编译
'com.squareup.retrofit2:retrofit:2.1.0'
OkHttpClient.Builder builder = new OkHttpClient.Builder();
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.networkInterceptors().add(httpLoggingInterceptor);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(httpLoggingInterceptor).build();
retrofit = new Retrofit.Builder()
.baseUrl(NetworkConstsParkCloud.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
没有捷径,没有okhttp就不能使用改造,从4.4开始,Android上的HttpUrlConnection无论如何都使用OkHttp:
https://github.com/google/agera/issues/22