Network communication frame interpretation http (HttpClient, HttpURLConnection, OKHttp, Unirest, Volley, Xutils, Retrofit)

A, HttpClient and HttpURLConnection, URLConnection

  HttpURLConnection the URLConnection succession, the bottom socket, the most primitive communication, using an HTTP request HttpURLConnection greatest advantage is not necessary to introduce additional dependencies. But it can not provide additional functionality, such as cookie, log in, but also a lack of connection pool management, control and other mechanical properties of the domain name? Support.

       Apache HttpClient is a project, a lot package level details. Apache HttpComponents HttpClient, formerly known as Apache Commons HttpClient, but Apache Commons HttpClient has stopped development, if you're still using it, switch to the Apache HttpComponents HttpClient up. Compared to traditional JDK comes with URLConnection HttpClient, increased ease of use and flexibility, it is not only the client sends an HTTP request easier, but also facilitates developers to test interface (Http-based protocol), is to enhance the development of efficiency, and convenience to improve the robustness of the code.

      JDK comes HttpURLConnection standard library;. Apache HttpComponents HttpClient, and based on the warpper library, such as a non-Unirest HTTP client component library based on Apache HttpComponents HttpClient, a large number of code rewrite application layer, a typical representative OkHttp HttpURLConnectio..

 

Two, OKHttp  

  Since the current version of Apache HttpComponents HttpClient does not support HTTP / 2, and HTTP / 2 for mobile clients, whether it is from a handshake delay, response delay, or have considerable resource overhead look attractive. This therefore gives high-level package and supports http client lib HTTP / 2 enough living space. One of the most typical to the number of OkHttp.

OkHttp-friendly interface design, support HTTP / 2, and automatic detection and recovery mechanisms in the weak network and non-network environment, therefore, is one of the Android APP development of the most widely used HTTP clilent lib.

On the other hand, the interface provided by Java 9 OkHttp in HttpClint the interface more similar to (strictly speaking, should be the Java 9 draws on interface design OkHttp and other open source library?), Therefore, for those who like to reduce dependence, develop love for the native standard library who, in Java 11?, the OkHttp from switching to the standard library is relatively easy. Therefore, after to OkHttp represented http library usage scenarios may be eroded part.

 

Three, Unirest
  Unirest a lightweight HTTP client library. Support for multiple languages, constructed and maintained by Mashape. Is a relatively rare class library, it is httpclient4 layer of the package, is called almost like okhttp. unirest From its name, you can see, a special service call to rest and students. It's a major feature provides multi-lingual call the same semantics. node / python / java / c # / ruby / oc these languages have common library called unirest, call the semantics are similar. Another great feature is directly integrated support for json serialization and deserialization, the results can be directly parsed json object or the object is returned json operable. Can refer https://www.cnblogs.com/zhangshihai1232/articles/6062507.html

 

Four, Volley
  Volley google is introduced in the network communications conference 2013 io the frame, especially for small data processing amount, frequent communications network operation. Advantage is that the interior of the package asynchronous thread, the main thread may directly request the network, and returns the processing result. At the same time you can cancel the request, easily extensible. The disadvantages are: the face of a request large amounts of data, such as downloading poor performance, do not support https. Volley bottom, in use, the following system for android2.3 httpclicent, the requesting network HttpUrlConnection android2.3 used above. Can refer https://blog.csdn.net/guolin_blog/article/details/17482095

 

Five, Xutils

 Xutils fire a few years ago was a relatively open-source framework, Xutils contains many useful tools, support for large file uploads, and more comprehensive request http protocol support, with flexible Orm, support event annotations and not affect code obfuscation . Xutils just come out when the program is really a lot of Cock wire ape welfare ah, integrates so many features powerful module, we really put it down, but with the upgrade and transformation of software development people thought of Android version, Xutils also exposed a lot of problems now with Xutils has not particularly much, if you want to use, then recommend the use of a relatively new Xutils3. Mainly for android, reference may https://blog.csdn.net/QPC908694753/article/details/77142124 .

 

 Six, Retrofit 

  Retrofit is a type of security for Android and Java platform web request frame. Retrofit by API Java interfaces and abstract to allow us to connect to REST web services become very easy. And also from OkHttp Square Company, dependent on the internal Retrofit OkHttp, but done on a more extended functions, such as the conversion function returns a result, the return data can be directly treated. You can refer https://juejin.im/post/5c0fbcf6518825642650b875  and https://www.jianshu.com/p/d7f0d9101b32


reference

https://juejin.im/post/5bae03b25188255c5442b66f

https://www.cnblogs.com/sharpest/p/7831350.html

https://blog.csdn.net/langtop/article/details/77972855

https://blog.csdn.net/imlsz/article/details/57616083

https://blog.csdn.net/bigbigsman/article/details/90707669

Guess you like

Origin www.cnblogs.com/yuluoxingkong/p/12330707.html