The version of the Apache HTTP client provided on stock Android was very very old.
Google Android 1.0 was released with a pre-BETA snapshot of Apache HttpClient. To coincide with the first Android release Apache HttpClient 4.0 APIs had to be frozen prematurely, while many of interfaces and internal structures were still not fully worked out. As Apache HttpClient 4.0 was maturing the project was expecting Google to incorporate the latest code improvements into their code tree. Unfortunately it did not happen.
If you don't want to switch over to a new API you can manually add a newer version of the Apache HttpClient library into your project to replace the old deprecated version in Android SDK < 22.
The easiest way to do this when targeting SDK 23+ is to use Marek Sebera's new Apache HttpClient package for Android (as suggested by Apache), which could potentially work as a drop-in replacement. Simply add the following dependency to your build.gradle file (updating the version number if appropriate):
compile "cz.msebera.android:httpclient:4.4.1.1"
and replace import org.apache.http.*
with import cz.msebera.android.httpclient.*
everywhere in your project.
Note that many classes from the old library are deprecated (e.g. HttpParams
, ThreadSafeClientConnManager
), so rewriting the code is probably going to be a better solution.
Edit: I found some cases where users were getting timeout exceptions when behind proxy servers after we updated to the newer Http client. Since the code is full of deprecated warnings everywhere, we decided that it wasn't worth the effort trying to fix the issue. I recommend testing very thoroughly before trying to put this into production.
As mentioned in other answers, a much better solution is to bite the bullet and switch over to either the native Android HttpUrlConnection
, or if that doesn't meet your needs, you can use the library OkHttp
, which is what HttpUrlConnection
is internally based upon anyway.