OKhttp和Retrofit源码分析
文章平均质量分 81
OKhttp和Retrofit源码分析
new_abc
这个作者很懒,什么都没留下…
展开
-
OKhttp源码解析---demo
首先来看一个例子:private static void OkHttpGet() { OkHttpClient mOkHttpClient = new OkHttpClient(); Request.Builder requestBuilder = new Request.Builder().url("http://www.baidu.com");原创 2016-11-02 11:31:42 · 1116 阅读 · 0 评论 -
OKhttp源码解析---OkHttpClient创建
OkHttpC客户端是通过new OkHttpClient()创建的,我们看下里面都做了什么首先是一些static的初始化private static final List DEFAULT_PROTOCOLS = Util.immutableList( Protocol.HTTP_2, Protocol.SPDY_3, Protocol.HTTP_1_1); privat原创 2016-11-02 12:31:27 · 4203 阅读 · 0 评论 -
OKhttp源码解析---Request创建
创建请求主要是一下几步 requestBuilder.method("GET", null); Request request = requestBuilder.build(); Call mcall = mOkHttpClient.newCall(request);先看new Request.Builder().url("http://w原创 2016-11-02 12:51:19 · 5574 阅读 · 0 评论 -
OKhttp源码解析---Request执行
执行一个request是调用它的enqueue并传递一个回调 mcall.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { System.out.println("onFailure原创 2016-11-02 15:26:58 · 1102 阅读 · 0 评论 -
OKhttp源码解析---拦截器之RetryAndFollowUpInterceptor
我们看下它的interceptpublic Response intercept(Chain chain) throws IOException { Request request = chain.request(); streamAllocation = new StreamAllocation( client.connectionPool(), creat原创 2016-11-02 16:22:04 · 2545 阅读 · 0 评论 -
OKhttp源码解析---拦截器之BridgeInterceptor
我们看下它的intercept函数public Response intercept(Chain chain) throws IOException { Request userRequest = chain.request(); Request.Builder requestBuilder = userRequest.newBuilder(); RequestBod原创 2016-11-02 16:40:36 · 1467 阅读 · 0 评论 -
OKhttp源码解析---拦截器之CacheInterceptor
同样,我们来看它的interceptpublic Response intercept(Chain chain) throws IOException { Response cacheCandidate = cache != null ? cache.get(chain.request()) : null; long now = System.原创 2016-11-02 17:16:15 · 2649 阅读 · 0 评论 -
OKhttp源码解析---拦截器之ConnectInterceptor
ConnectInterceptor主要负责和服务器建立连接我们看下他的interceptpublic Response intercept(Chain chain) throws IOException { RealInterceptorChain realChain = (RealInterceptorChain) chain; Request request = re原创 2016-11-02 17:56:38 · 2235 阅读 · 0 评论 -
OKhttp源码解析---拦截器之CallServerInterceptor
CallServerInterceptor负责发送请求和获取响应,我们看下它的intercept @Override public Response intercept(Chain chain) throws IOException { HttpStream httpStream = ((RealInterceptorChain) chain).httpStream(); St原创 2016-11-02 18:04:30 · 1650 阅读 · 2 评论 -
Retrofit源码解析---addConverterFactory和addCallAdapterFactory区别
我们先看下前面写的接口Call login( @Body User ueser);如果返回的是Observable格式,则这么定义接口:Observable login(@Body User ueser);从上面可以看到,Retrofit接口的返回值分为两部分,一部分是前面的Call或者Observable,另一部分是String。addCallAdapterFactory影响的就是第原创 2016-11-03 16:29:54 · 23944 阅读 · 0 评论 -
Retrofit源码解析---初始化
ss原创 2016-11-03 16:20:16 · 1450 阅读 · 0 评论 -
Retrofit源码解析---执行请求(DefaultCallAdapterFactory)
dd原创 2016-11-03 16:21:19 · 2385 阅读 · 0 评论 -
Retrofit源码解析---执行请求(RxJavaCallAdapterFactory)
d原创 2016-11-03 16:21:40 · 2283 阅读 · 0 评论