- org.apache.http.impl.client.DefaultHttpClient - 主要使用 Apache 的 HttpClient
- Default implementation of an HTTP client.
- This class replaces HttpClient in HttpClient 3.
- android.net.http.AndroidHttpClient - API 8 - 主要使用 Apache 的 HttpClient
- Implementation of the Apache DefaultHttpClient that is configured with reasonable default settings and registered schemes for Android, and also lets the user add HttpRequestInterceptor classes.
- Don't create this directly, use the newInstance(String) factory method.
Their implementation is stable and they have few bugs. But Android Team is not actively working on Apache HTTP Client.
- org.apache.http.client.httpClient - 做的事 就是 browser 送出 url 的那個動作
- Interface for an HTTP client. HTTP clients encapsulate a smorgasbord of objects required to execute HTTP requests while handling cookies, authentication, connection management, and other features.
- Thread safety of HTTP clients depends on the implementation and configuration of the specific client.
- abstract java.net.URLConnection
- Instances of URLConnection are not reusable: you must use a different instance for each connection to a resource.
- An URLConnection for HTTP (RFC 2616) used to send and receive data over the web. Data may be of any type and length.
- java.net.HttpURLConnection extends URLConnection
- This class may be used to send and receive streaming data whose length is not known in advance.
- Is a general-purpose, lightweight HTTP client suitable for most applications.
- Prior to Froyo, HttpURLConnection had some frustrating bugs.
- Work around this by disabling connection pooling (Refer: Android’s HTTP Clients | Android Developers Blog)
- In Gingerbread, we added transparent response compression.
- In Ice Cream Sandwich, we are adding a response cache.
- How to choose?
- Eclair and Froyo - Apache HTTP client that has fewer bugs.
- For Gingerbread and better - HttpURLConnection.
- Its simple API and small size makes it great fit for Android.
- Transparent compression and response caching reduce network use, improve speed and save battery.
- Android Team will be spending our energy going forward.
* Reference
- Android’s HTTP Clients | Android Developers Blog
- Android 上的 HTTP 服務相關函式 (I)
- Android 上的 HTTP 服務相關函式 (II)
- Android 上的 HTTP 服務相關函式 (III)
沒有留言:
張貼留言