我有一个Android应用,主屏幕向服务器发出的请求很少(enqueue(5-10个请求取决于应用逻辑)),但是当我增加一个请求时,我无法从日志中获取响应。 我配置以下代码:
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
@Override
public void log(String message) {
Log.d(TAG, message);
}
});
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
httpBuilder.addInterceptor(httpLoggingInterceptor);
ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.tlsVersions(TlsVersion.TLS_1_2)
.cipherSuites(
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256)
.build();
httpBuilder
.readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
.writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
httpBuilder.connectionSpecs(Collections.singletonList(spec));
我通过以下方式致电请求
Call<ResponseBody> call = getCallRequest();
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
// process failure case
}
});
但是HttpLoggingInterceptor不会记录此请求的响应,因为 <-正在记录...。 并非在所有请求中都发生,有时还可以,所以我认为原因是连接池,但是我通过添加以下行来尝试代码:
httpBuilder.connectionPool(new ConnectionPool(10, 5L, TimeUnit.MINUTES));
,但不起作用。请帮助我找出解决此问题的方法。非常感谢!