setLevel okhttp LoggingInterceptor deprecated

∥☆過路亽.° 提交于 2019-12-22 03:52:23

问题


setLevel(okhttp3.logging.HttpLoggingInterceptor.Level)' is deprecated

what should replace with setLevel? to remove the deprecated issue


回答1:


According to the documentation "Moved to var. Replace setLevel(...) with level(...) to fix Java",

Replace setLevel(...) with level(...) will fix this issue

example :

HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.level(HttpLoggingInterceptor.Level.BODY);

Happy coding :)




回答2:


for Kotlin

replace :

val logger: HttpLoggingInterceptor =
HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)  //Logging Interceptor

with :

val logger = HttpLoggingInterceptor()
logger.level = HttpLoggingInterceptor.Level.BODY

Add your inceptor to okHttpClient

val okkHttpclient = OkHttpClient.Builder()
                .addInterceptor(networkConnectionInterceptor)
                .addInterceptor(logger)
                .build()

Happy Coding...



来源:https://stackoverflow.com/questions/56840495/setlevel-okhttp-logginginterceptor-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!