Official comments:
1) Apache httpclient is highly efficient and stable, but the maintenance cost is high. Therefore, the android development team is unwilling to maintain the library, but switched to httpurlconnection, Which is lighter;
2) httpurlconnection is lightweight, flexible, and easy to expand. It had such a bug before 2.2,
See http://code.google.com/p/android/issues/detail for details? Id = 2939
private void disableConnectionReuseIfNecessary() { // HTTP connection reuse which was buggy pre-froyo if (Integer.parseInt(Build.VERSION.SDK) < Build.VERSION_CODES.FROYO) {
System.setProperty("http.keepAlive", "false"); }}
3) In gingerbread, httpurlconnection adds processing for the compressed packet header. The server can use gzip. For details, see:
Http://developer.android.com/reference/java/net/HttpURLConnection.html
4) improvements have been made in httpurlconection after 3.0 and 4.0, such as HTTPS support,
In 4.0, cache support is also added, for example:
private void enableHttpResponseCache() { try { long httpCacheSize = 10 * 1024 * 1024; // 10 MiB File httpCacheDir = new File(getCacheDir(), "http"); Class.forName("android.net.http.HttpResponseCache").getMethod("install", File.class, long.class.invoke(null, httpCacheDir, httpCacheSize); } catch (Exception httpResponseCacheNotAvailable) { }}
5) in the android SDK, httpclient uses 4.0beta2. I have to say there are some bugs in this version:
I. Auth caching;
Ii. In SDK 4.0, WiFi and 3G are enabled at the same time. Theoretically, the network interface should go through WiFi but go through proxy, leading to network access failure;
The only way to solve the above problem is to introduce.
Personal Opinion:
My Opinions on Google's official developers are not similar. I am more inclined to use httpclient, because we can understand from the explanation of poolingclientconnectionmanager:
Manages a pool of {@ link operatedclientconnection client connections} and is able to service connection requests from multiple execution threads.
Connections are pooled on a per route basis. A request for a route which already the manager has persistent connections for available in the pool will be services by leasing a connection from the pool rather than creating a brand new connection.
This can save us time for frequent connection establishment. In our apps, we often use drop-down lists to call interfaces. The cost of repeatedly creating connections can be imagined.
Please pay attention to my later articles. I will make a comprehensive analysis on the httpclient 4.2 architecture of Apache.