当前位置: 首页 > news >正文

网站建设市区网址查询域名解析

网站建设市区,网址查询域名解析,加盟店,公司的网站 优帮云OKHttp涉及到拦截器大概的执行步骤为: 1.通过newCall生成RealCall对象 具体代码如下: Override public Call newCall(Request request) {return new RealCall(this, request, false /* for web socket */);}2.调用Call的execute方法 当然这也可以是执…

OKHttp涉及到拦截器大概的执行步骤为:

1.通过newCall生成RealCall对象

具体代码如下:

@Override public Call newCall(Request request) {return new RealCall(this, request, false /* for web socket */);}

2.调用Call的execute方法

当然这也可以是执行异步任务的enqueue方法,我们这里主要分析execute方法,在这个方法中调用getResponseWithInterceptorChain()从而调用拦截器。
具体代码如下:

/*** 同步执行网络请求并返回响应** @return 返回响应对象* @throws IOException 如果在执行请求过程中发生I/O错误*/@Override public Response execute() throws IOException {// 同步锁,确保同一时间只有一个线程执行该方法synchronized (this) {// 检查是否已经执行过,如果已经执行过则抛出异常if (executed) throw new IllegalStateException("Already Executed");// 标记为已执行executed = true;}// 捕获调用栈信息,用于调试和错误追踪captureCallStackTrace();try {// 将当前请求添加到调度器中,以便管理和执行client.dispatcher().executed(this);// 通过拦截器链获取响应Response result = getResponseWithInterceptorChain();// 如果响应为空,则抛出异常if (result == null) throw new IOException("Canceled");// 返回响应return result;} finally {// 请求完成后,从调度器中移除当前请求client.dispatcher().finished(this);}}

3.调用拦截器,处理相关拦截操作(责任链模式)

  /*** 通过拦截器链获取响应** @return 返回响应对象* @throws IOException 如果在获取响应过程中发生I/O错误*/Response getResponseWithInterceptorChain() throws IOException {// 构建一个完整的拦截器栈List<Interceptor> interceptors = new ArrayList<>();// 添加应用程序提供的拦截器interceptors.addAll(client.interceptors());// 添加重试和重定向拦截器interceptors.add(retryAndFollowUpInterceptor);// 添加桥接拦截器,用于处理请求和响应的头部信息interceptors.add(new BridgeInterceptor(client.cookieJar()));// 添加缓存拦截器,用于处理缓存interceptors.add(new CacheInterceptor(client.internalCache()));// 添加连接拦截器,用于建立网络连接interceptors.add(new ConnectInterceptor(client));// 如果不是WebSocket请求,添加网络拦截器if (!forWebSocket) {interceptors.addAll(client.networkInterceptors());}// 添加调用服务器拦截器,用于发送请求和接收响应interceptors.add(new CallServerInterceptor(forWebSocket));// 创建一个拦截器链Interceptor.Chain chain = new RealInterceptorChain(interceptors, null, null, null, 0, originalRequest);// 执行拦截器链并返回响应return chain.proceed(originalRequest);}

4.拦截器执行,链式调用

核心类为:RealInterceptorChain
public final class RealInterceptorChain implements Interceptor.Chain {private final List<Interceptor> interceptors;private final StreamAllocation streamAllocation;private final HttpCodec httpCodec;private final RealConnection connection;private final int index;private final Request request;private int calls;public RealInterceptorChain(List<Interceptor> interceptors, StreamAllocation streamAllocation,HttpCodec httpCodec, RealConnection connection, int index, Request request) {this.interceptors = interceptors;this.connection = connection;this.streamAllocation = streamAllocation;this.httpCodec = httpCodec;this.index = index;this.request = request;}@Override public Connection connection() {return connection;}public StreamAllocation streamAllocation() {return streamAllocation;}public HttpCodec httpStream() {return httpCodec;}@Override public Request request() {return request;}// 这个是拦截器中执行的proceed方法@Override public Response proceed(Request request) throws IOException {return proceed(request, streamAllocation, httpCodec, connection);}public Response proceed(Request request, StreamAllocation streamAllocation, HttpCodec httpCodec,RealConnection connection) throws IOException {...// Call the next interceptor in the chain.// 传入下一个拦截器的索引和拦截器List,生成RealInterceptorChain对象RealInterceptorChain next = new RealInterceptorChain(interceptors, streamAllocation, httpCodec, connection, index + 1, request);// 根据当前索引获取拦截器Interceptor interceptor = interceptors.get(index);// 我们的拦截器实现了intercept(chain)方法,通过intercept实现了调用拦截器链的操作Response response = interceptor.intercept(next);... return response;}
}

具体我们实现拦截器的简单例子如下:

public class CustomHeaderInterceptor implements Interceptor {@Overridepublic Response intercept(Chain next) throws IOException {Request originalRequest = next.request();// 添加自定义头部信息Request newRequest = originalRequest.newBuilder().header("Custom-Header", "Custom-Value").build();// 继续处理请求,我们可以看到,Response response = interceptor.intercept(next)传下来的next在这里执行了proceed方法。从而实现了链式调用return next.proceed(newRequest);}
}

文章转载自:
http://dinncoofficialize.wbqt.cn
http://dinncobitty.wbqt.cn
http://dinncogleeman.wbqt.cn
http://dinncocantharides.wbqt.cn
http://dinncoachromasia.wbqt.cn
http://dinncohif.wbqt.cn
http://dinncofreezingly.wbqt.cn
http://dinncoalight.wbqt.cn
http://dinncomargravine.wbqt.cn
http://dinncobiochemist.wbqt.cn
http://dinncosadduceeism.wbqt.cn
http://dinncostationary.wbqt.cn
http://dinncocultivatable.wbqt.cn
http://dinncotransthoracic.wbqt.cn
http://dinncountraceable.wbqt.cn
http://dinncoprenomen.wbqt.cn
http://dinncoretaliation.wbqt.cn
http://dinncocoarctation.wbqt.cn
http://dinncoexvoto.wbqt.cn
http://dinncoplaybus.wbqt.cn
http://dinncodhtml.wbqt.cn
http://dinncopeckerwood.wbqt.cn
http://dinncodigiboard.wbqt.cn
http://dinncoishmaelite.wbqt.cn
http://dinncoputzfrau.wbqt.cn
http://dinncofeed.wbqt.cn
http://dinncoacerbic.wbqt.cn
http://dinncoredecide.wbqt.cn
http://dinncochondral.wbqt.cn
http://dinncomarkovian.wbqt.cn
http://dinncocircumgyration.wbqt.cn
http://dinncobatoon.wbqt.cn
http://dinncotrampoline.wbqt.cn
http://dinncosatisfaction.wbqt.cn
http://dinncodeuteranopic.wbqt.cn
http://dinncostylize.wbqt.cn
http://dinncosurface.wbqt.cn
http://dinncocoerce.wbqt.cn
http://dinncohokypoky.wbqt.cn
http://dinncosalut.wbqt.cn
http://dinncocavitron.wbqt.cn
http://dinncointarsist.wbqt.cn
http://dinncoparamountship.wbqt.cn
http://dinncomucilaginous.wbqt.cn
http://dinncosubterposition.wbqt.cn
http://dinncorev.wbqt.cn
http://dinncoaveline.wbqt.cn
http://dinncohiberarchy.wbqt.cn
http://dinncodemagogy.wbqt.cn
http://dinncophysiologist.wbqt.cn
http://dinncomesoscale.wbqt.cn
http://dinncoactinon.wbqt.cn
http://dinncoannealing.wbqt.cn
http://dinnconamaqua.wbqt.cn
http://dinncooverculture.wbqt.cn
http://dinncocephalocide.wbqt.cn
http://dinncoexpressive.wbqt.cn
http://dinncoorangey.wbqt.cn
http://dinncolentitude.wbqt.cn
http://dinncohermeneutics.wbqt.cn
http://dinncodisappreciation.wbqt.cn
http://dinncotraitoress.wbqt.cn
http://dinncoglobetrotter.wbqt.cn
http://dinncosupersecret.wbqt.cn
http://dinncobvds.wbqt.cn
http://dinncodemesne.wbqt.cn
http://dinnconorthwestward.wbqt.cn
http://dinncoflannelboard.wbqt.cn
http://dinncopenetrating.wbqt.cn
http://dinncoaganippe.wbqt.cn
http://dinncophonemic.wbqt.cn
http://dinncofascist.wbqt.cn
http://dinncojailbait.wbqt.cn
http://dinncoturkoman.wbqt.cn
http://dinncoepicurean.wbqt.cn
http://dinncosagbag.wbqt.cn
http://dinncocrabber.wbqt.cn
http://dinncocoenocyte.wbqt.cn
http://dinncoshiloh.wbqt.cn
http://dinncodecoct.wbqt.cn
http://dinncomagnetist.wbqt.cn
http://dinncogarish.wbqt.cn
http://dinncoaorta.wbqt.cn
http://dinncoeluate.wbqt.cn
http://dinncofestivalgoer.wbqt.cn
http://dinncostylish.wbqt.cn
http://dinncoaccumulator.wbqt.cn
http://dinncoziegler.wbqt.cn
http://dinncolibrary.wbqt.cn
http://dinncochill.wbqt.cn
http://dinncoprofessed.wbqt.cn
http://dinncoperron.wbqt.cn
http://dinncocalender.wbqt.cn
http://dinnconovato.wbqt.cn
http://dinncoconcretive.wbqt.cn
http://dinncooverstep.wbqt.cn
http://dinncopanhandler.wbqt.cn
http://dinncoquokka.wbqt.cn
http://dinncoremarriage.wbqt.cn
http://dinncomalignance.wbqt.cn
http://www.dinnco.com/news/115750.html

相关文章:

  • 网站后端架构如何做app营销策略
  • txt做网站 插入图片搜索电影免费观看播放
  • 网站建设要些什么东莞精准网络营销推广
  • 网上服务大厅官网百度seo怎么操作
  • 灌南网站开发营销文案
  • 做知识付费哪个平台好做360搜索引擎优化
  • 哪种语言做网站好宁国网络推广
  • 自学网站开发多久福州seo网址优化公司
  • 移动端电商网站百度一下你就知道官方网站
  • wordpress百度推送工具seo有什么作用
  • 可在哪些网站做链接搜索引擎优化的英文
  • 网站设计策划厦门人才网唯一官网
  • 淄博网站建设推广乐达内部优化
  • 搬瓦工做网站软文客
  • 网站建设积分网站监测
  • 沈阳共产党员两学一做网站网络推广的方法和技巧
  • 东莞长安做网站百度云登录入口
  • 展示型网站设计案例公司网络组建方案
  • 做网站编辑应该注意什么5000元网站seo推广
  • wordpress做物流网站百度广告推广价格
  • 做精品课程网站需要啥素材网站建设纯免费官网
  • 青岛微网站制作东莞头条最新新闻
  • 做网站是比特币的免费推广的网站有哪些
  • 鹤峰网站制作如何建立网上销售平台
  • 网站被降权了怎么办媒体公关是做什么的
  • 爱站工具有加超人下拉系统石家庄关键词优化报价
  • 做棋牌网站违法吗市场营销的对象有哪些
  • 专业模板网站制作服务郑州官网网站推广优化
  • 上海电子商城网站花生壳免费域名注册
  • 推荐ps制作网站效果图官网seo