gpt4 book ai didi

android - HttpLoggingInterceptor 不使用改造 2 记录

转载 作者:IT老高 更新时间:2023-10-28 13:47:16 32 4
gpt4 key购买 nike

我正在尝试使用 refrofit2、kotlin 和 logging-interceptor 记录所有请求(使用网络拦截器):

  • 改造:“2.0.2”
  • okhttp3 : "3.2.0"
  • com.squareup.okhttp3:logging-interceptor 3.2.0

喜欢:

val interceptor = HttpLoggingInterceptor()
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

val okHttpClient = OkHttpClient.Builder()
.addNetworkInterceptor(interceptor) // same for .addInterceptor(...)
.connectTimeout(30, TimeUnit.SECONDS) //Backend is really slow
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build()

sRestAdapter = Retrofit.Builder()
.client(okHttpClient)
.baseUrl(if (host.endsWith("/")) host else "$host/")
.addConverterFactory(GsonConverterFactory.create(gson()))
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build()

它只是打印:

D/OkHttp: --> GET url...
D/OkHttp: --> END GET

发生了什么?

--------------- 编辑--------

记录器没有显示在主线程上执行请求的错误,所以要小心。

最佳答案

private val interceptor = run {
val httpLoggingInterceptor = HttpLoggingInterceptor()
httpLoggingInterceptor.apply {
httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
}
}


private val okHttpClient = OkHttpClient.Builder()
.addNetworkInterceptor(interceptor) // same for .addInterceptor(...)
.connectTimeout(30, TimeUnit.SECONDS) //Backend is really slow
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build()

关于android - HttpLoggingInterceptor 不使用改造 2 记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37105278/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com