OkHttp拦截器原理

xiaoxiao2021-02-28  38

学习自https://www.cnblogs.com/LuLei1990/p/5534791.html

所以request就是拦截到的请求

response就是拦截到的回复

这里留下一个疑问,这个方法回调的时间点是哪里?显然request和response不在一个时间上

addNetworkInterceptor添加的是网络拦截器,他会在在request和resposne是分别被调用一次,addinterceptor添加的是application拦截器,他只会在response被调用一次

日志拦截器demo

拦截器

使用

原理

new Call

RealCall.execute,红色:把请求放入同步双端队列

getResponseWithInterceptorChain

proceed,当拦截器集合不为空,一个个加进去;拦截器读取完了,再进行真正的请求

转载请注明原文地址: https://www.6miu.com/read-2628679.html

最新回复(0)