美文网首页
RequestBody writeTo 执行两次问题(722)

RequestBody writeTo 执行两次问题(722)

作者: Qin0821 | 来源:发表于2018-06-15 19:11 被阅读0次

在OkHttp里加入HttpLoggingInterceptor会调用了wirteTo方法,导致会再次执行UploadFileRequestBody.writeto方法重复写入数据。
通过调整拦截器等级可以解决这个问题。

val loggingInterceptor = HttpLoggingInterceptor(HttpLoggingInterceptor.Logger {
            // 打印retrofit日志
            Log.i("RetrofitLog", "retrofitBack = $it")
        })
        // 不要设置成BODY,会导致writeTo调用两次
loggingInterceptor.level = HttpLoggingInterceptor.Level.HEADERS

从BODY改成HEADERS解决了重复调用问题。

BASIC
 请求/响应行

HEADER
 请求/响应行 + 头

BODY
 请求/响应行 + 头 + 体

相关文章

网友评论

      本文标题:RequestBody writeTo 执行两次问题(722)

      本文链接:https://www.haomeiwen.com/subject/rtmpeftx.html