10
android-网络框架解析–第0篇OkHttp(4.0.x)—架构介绍
source link: http://www.demanmath.com/index.php/2020/10/12/android-wangluokuangjiajiexi-di0pianokhttp4-0-x-jiagoujieshao/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
OkHttpClient.Builder
产生OkHttpClient的builder设计模式。
原则上OkHttpClient可以配置的内容,都在里面。
Dispatcher
调度并发的。创建线程池。request上限是64个。
android的网络请求并发数是多少?
connectionPool
链接池,可以加快相同host的链接速度。从app角度来看,绝大部分host,都是同一个,公司自己的。所以这个优化很有必要。
interceptors
自定义的interceptors,也就是自定义的拦截器,都是存放在这里。
这些拦截器是最先启动的。
networkInterceptors
同样是拦截器,当网络链接以后,我们需要链接,就用到这个。
eventListenerFactory
用来创建时间的回调,核心请求的过程,都会回调。
retryOnConnectionFailure
设置是否重试?
Authenticator
解析ip地址
proxy
代理,默认不需要。
socketFactory & sslSocketFactory
socket 产生,okhttp使用socket进行通信,一般情况使用默认就可以,特殊情况可以配置。
X509TrustManager
网络通信的过程,隐藏在这个表象里面。
如果自定义自己的factory,是否就可以拿到所有的socket。
ConnectionSpec
TLS版本配置等。
Protocol
http的版本
hostnameVerifier
OkHostnameVerifier hostname的认证
CertificatePinner
验证证书使用
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK