I am using DefaultHttpClient
in my current app.
I read this article which states that the DefaultHttpClient
is deprecated: http://developer.android.com/reference/org/apache/http/impl/client/DefaultHttpClient.html
It points to this website: http://android-developers.blogspot.com/2011/09/androids-http-clients.html?m=1 which is too old and written in 2011.
I am going to drop using DefaultHttpClient
and follow this article which uses Apache’s HttpClient
: http://loopj.com/android-async-http/
I wonder if this is the right path to take when programming in 2015 targeting android API 19 and above.
It's Time to switch over to OkHttp which does HTTP efficiently and makes your stuff load faster and saves bandwidth.It supports both synchronous blocking calls and async calls with callbacks.
OkHttp supports Android 2.3 and above.
Add the below dependency to your android Project.
Ok I waited for a week and so and did all lots of researches. I think I have found the answer.
I strongly advise for beginners and even professional Android programmers to know the existence of very helpful library called Retrofit:
Extensive document is present at http://square.github.io/retrofit/
The Stack overflow also has samples for almost everything one need to do over a network to contact a remote REST service.
It is better to stop using HttpURLConnection and AsyncTask. Retrofit is way faster and supports all failure situations out of the box.
You should switch to HttpURLConnection. It requires slightly more code, but not so much. In SDK 22 they already deprecated HttpClient, and even if you target SDK 19, when compiling with 22 you get warnings.
Just speculation (cannot find any source for this now) but I guess they will not do any fixing in the deprecated libraries, so any security problems or bugs will remain unfixed.
Option 1 : Volley
Volley's benefits :
Option 2 : OkHttp
Some of the features listed in its documentation :
As well as linking to that blog, the docs recommend you use URL.openConnection which has been around since API level 1.