java.lang.IllegalStateException:
作者:
提丶米 | 来源:发表于
2018-09-10 23:27 被阅读8次
自定义Okhttp拦截器遇到的问题
- 当我们重写Interceptor的intercept方法时,如果是拦截了返回(Response),调用Response的string()方法如下图,原因是:response.body().string()只能请求一次,请求过后,就会关闭,再次调用response.body().string()就会报close异常。
String content= response.body().string();
- 解决方案:重新builder一个Response ,重新设置一个response。
Response response = chain.proceed(newRequest);
MediaType mediaType = response.body().contentType();
String content= response.body().string();
LogUitls.e("tag", content);
return response.newBuilder()
.body(ResponseBody.create(mediaType, content))
.build();
本文标题:java.lang.IllegalStateException:
本文链接:https://www.haomeiwen.com/subject/wozegftx.html
网友评论