'setLevel(okhttp3.logging.HttpLoggingInterceptor.Level)'已经被弃用
应该使用什么方法来替代setLevel以解决弃用问题?
setLevel(...)
替换为level(...)
将解决此问题。HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.level(HttpLoggingInterceptor.Level.BODY);
在 Kotlin 中
val logging = HttpLoggingInterceptor()
logging.level = HttpLoggingInterceptor.Level.BODY
愉快编码 :)
private val loggingInterceptor = HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}
var client : OkHttpClient = OkHttpClient.Builder().addInterceptor(loggingInterceptor).build()
Kotlin编程语言
替换为:
val logger: HttpLoggingInterceptor =
HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY) //Logging Interceptor
使用:
val logger = HttpLoggingInterceptor()
logger.level = HttpLoggingInterceptor.Level.BODY
将您的拦截器添加到okHttpClient
val okkHttpclient = OkHttpClient.Builder()
.addInterceptor(networkConnectionInterceptor)
.addInterceptor(logger)
.build()
编程愉快...