我遇到了一个奇怪的问题。 OkHttp 给出了这样的日志:
I/System.out: [OkHttp] sendRequest>>
I/System.out: [OkHttp] sendRequest<<
但是我在客户端初始化时声明了日志拦截器。
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE);
OkHttpClient.Builder client = new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.addInterceptor(chain -> {
Request original = chain.request();
Request.Builder builder = original.newBuilder()
.header("Authorization", Credentials.basic(config.login(), config.password()));
Request request = builder.build();
return chain.proceed(request);
})
.addInterceptor(httpLoggingInterceptor);
return new Retrofit.Builder()
.baseUrl(config.getServer())
.callbackExecutor(Executors.newSingleThreadExecutor())
.addConverterFactory(getMoshiConverterFactory())
.client(client.build())
.build();
我的 Gradle 包含:
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-moshi:2.3.0'
implementation 'com.squareup.moshi:moshi:1.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.7.0'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.7.0'
我做错了什么吗?