官方意见:

1) apache httpclient高效稳定,但是维护成本高昂,故android 开发团队不愿意在维护该库而是转投更为轻便的httpurlconnection;

2) httpurlconnection比较轻便,灵活和易于扩展,它在2.2前存在这样一个BUG,
详见http://code.google.com/p/android/issues/detail?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) 在Gingerbread中,httpurlconnection会增加对压缩报文头的处理,服务端可以用GZIP,详细见:
http://developer.android.com/reference/java/net/HttpURLConnection.html

4) 在HTTPURLCONECTION中,在3.0后以及4.0中都进行了改善,如对HTTPS的支持,
在4.0中,还增加了对缓存的支持,比如:
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)在androidSDk中httpclient使用的是4.0beta2,我不得不说这个版本里面有些蛋疼的bug:

I.auth caching;

II.在4.0上的sdk,将wifi和3g同时打开,理论上来说,网络接口应该走wifi,但是却走了代理,导致访问服务器网络失败;

解决上面问题的唯一办法就是引入“http://code.google.com/p/httpclientandroidlib/”中的库,然后修改相应的类,典型的例子就是ThreadSafeClientConnManager变成了PoolingClientConnectionManager

个人意见:

我对谷歌官方开发同事的意见有点不敢雷同,个人更倾向于使用httpclient,因为从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.

可以节省我们频繁建立连接的时间,往往在我们的app里面更多的情况是,不断的去下拉列表调用接口,反复创建连接的代价可想而知。

请注意关注我后面的文章,我会对apache的httpclient 4.2版本的架构做全面地分析。


更多相关文章

  1. Android(安卓)MVP+Retrofit(封装)+RxJava实例
  2. 聊聊Service(二)
  3. Android(安卓)架构
  4. Android(安卓)Jetpack-Lifecycle
  5. 第五章(6)Libgdx应用框架之接口
  6. Android图形系统之libui
  7. Android(安卓)framework/base 下添加新的接口
  8. Android(安卓)Jetpack 之 LifeCycle
  9. Android(安卓)之事件处理(二)基于监听的事件处理

随机推荐

  1. H5做的商城客户端,效果很不错
  2. IDA Pro 远程调试Android进程环境配置
  3. Android P 中的新文本特性
  4. Android显示提示信息,实现两个界面之间的
  5. Android ADB的使用
  6. Android 控件一 TextView
  7. Android 控件二 Button
  8. 【Android(安卓)开发教程】自定义Content
  9. Android Stuido 使用WIFI测试
  10. android activity 生命周期