简体   繁体   English

为什么Volley Library通常与okHttp Library结合使用?

[英]Why is Volley Library usually combined with okHttp Library?

Why is Volley usually combined with okHttp? 为什么Volley通常与okHttp结合? Why is it done like this? 为什么这样做?

eg: 例如:

   OkHttpClient client = new OkHttpClient();
   client.networkInterceptors().add(new StethoInterceptor());
   mRequestQueue = Volley.newRequestQueue(context, new OkHttpStack(client));

Volley needs an HttpStack when you create the RequestQueue . 创建RequestQueue时, Volley需要一个HttpStack

If you don't provide one, Volley will create an stack depending on your API level: If you are running API 9 or below it'll be based on the AndroidHttpClient. 如果您没有提供,则Volley将根据您的API级别创建一个堆栈:如果您运行的是API 9或更低版本,它将基于AndroidHttpClient。 If you are running API 10 or above it'll be based on HttpURLConnection. 如果您运行的是API 10或更高版本,它将基于HttpURLConnection。

OkHttp is an modern, fast and efficient Http client which supports HTTP/2 and SPDY and does a lot of stuff for you like connection pooling, gziping, caching… and so on. OkHttp是一个现代,快速,高效的Http客户端,支持HTTP / 2和SPDY,为你做很多事情,比如连接池,gziping,缓存......等等。 OkHttp acts like the transport layer. OkHttp就像传输层一样。

OkHttp uses Okio , a library that complements java.io and java.nio to make it much easier to access, store, and process your data. OkHttp使用奥基奥 ,即补充java.io和java.nio中,以使它更容易访问,存储和处理数据的库。

For those reasons I recommend you to use and OkHttp Stack. 出于这些原因,我建议你使用和OkHttp Stack。 I'm using this one that does not use okhttp-urlconnection. 我用这一个不使用okhttp-的URLConnection。

I've written an article about using OkHttp, Volley and Gson for Android networking that you might find interesting. 我写过一篇关于使用OkHttp,Volley和Gson进行Android网络的文章,你可能会感兴趣。

阅读本文为什么okhttp适合运输 - 然后你会知道为什么它经常与凌空相结合

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM