I have to download an internet page with an android application and i'm getting a difficult time determining whether or not to make use of the android apache htto client or java's URLConnection.

Any ideas?


For many things I'd state that HttpClient is what you want. However you will find some situations and edge cases when I'd fall to a URLConnection. Good examples of edge cases here and here

An identical question continues to be requested before: httpclient versus httpurlconnection. I'd think that HttpUrlConnection is sort of faster because the HttpClient is made on the top from the standard Java libraries. However I'd find HttpClient code much faster and simpler to create and keep. Based on a comments below, the core aspects of HttpClient happen to be performance optimized.

If performance is really a major concern your best choice would be to write two clients, one using each method, then benchmark both of them. Should you choose this, please tell us the outcomes.

in Gingerbread and then, HttpURLConnection is what you want. consider Apache HttpClient deprecated. (also observe that Android does not use HttpClient 4.1, pointed out in another comment.)

for those who have a situation where Apache HttpClient is faster, report it as being a bug here: http://code.google.com/p/android/issues/list

Google has quietly deprecated Apache HTTP client usage since Gingerbread: http://android-designers.blogspot.com/2011/09/androids-http-clients.html. Even though they did not measure the level with deprecated annotation, they suggest you to employ HttpURLConnection for brand new programs as: it is where we [Google] will be spending our energy going forward.

Personally I do not like this decision and prefer to stay with HttpClient 4.1+, because it is faster, have less bugs and it is up-to-date regularly. Even though you can't upgrade system library to version 4.1, you can HttpClient jar for your Android project (because the additional benefit this could permit you to not rely on Google bug fixes and vendor updates). There's one pitfall however: to avoid possible collisions with built-in library you need to relabel httpclient packages using JarJar tool. Switched out someone already did this (rebranded jar and Android library projects are for sale to download):


This can be a repackaging of HttpClient 4.1 for Android. The version of HttpClient within the Android SDK is 4.0beta2. There has been several updates to HttpClient plus some much-needed bugfixes like auth caching because the 4.0beta.

Since Google has deprecated HttpClient in support of Java standard HttpURLConnection I produced a script to transform a regular discharge of Apache's HttpClient into an Android library.

Changes to stock HttpClient

  • Re-named all packages org.apache.http to ch.boye.httpclientandroidlib
  • Erased all classes determined by org.ietf.* (SPNEGO authentication)
  • Changed org.apache.commons.codec.binary.Base64 with android.util.Base64
  • Produced a brand new class HttpClientAndroidLog to exchange org.apache.commons.logging