I'm looking for a library that handles HTTP POST, multipart etc. Is there a de-facto standard library to make these requests easier on android?
-
2I've come across this Asynchronous HTTP Library recently http://loopj.com/android-async-http/ haven't tried yet. It is built to make asynchronous HTTP processing easier. – rineez May 01 '12 at 20:09
-
Very good library for Asynchronous requests, Only issues I have with it is that I cant access the response headers of my http request's response. – Zapnologica Aug 15 '13 at 13:03
-
1Don't use Loopj Async Http Client, it really sucks, threads die and you don't even know, very bad thread pooling. ION is far better use this https://github.com/koush/ion/ – AZ_ Mar 19 '14 at 03:21
-
1OKHttp looks as easy as possible: https://square.github.io/okhttp/: ```OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(url) .build(); Response response = client.newCall(request).execute(); return response.body().string(); ``` – serv-inc Jul 20 '18 at 15:02
7 Answers
Take a look at DroidFu, and in particular the DroidFu HTTP components. They're a fairly thin wrapper around the Apache Commons HTTP stuff, but they fit most needs pretty well. It includes some niceties like optional HTTP and model caching, and even "why isn't this built in to the platform" stuff like GZip. (An aside: android.net.AndroidHttPClient is a pretty good upgrade to the older stock DefaultHttpClient stuff when you need to drop down for a little more control, but it's Android 2.2+ only and is fairly underdocumented).
If you just need multipart with a minimum hassle, you can try android_multipart_post, though I've never tried it.
EDIT:
DroidFu is now discontinued. These days if I was starting a new project I'd almost certainly use Volley, with OKHttp if I needed more control (you can even use OKHttp as the transport layer for volley if you want to do both).

- 37,905
- 5
- 60
- 62
-
it is not clear how to set http post parameters eg name/value pairs in droidfu – hunterp Jun 01 '11 at 20:16
-
Use `BetterHttpRequest`'s `post` method to construct the request; pass it a URL and an HTTP entity (for simple name/value pairs, you can just pass a [`UrlEncodedFormEntity`](http://developer.android.com/reference/org/apache/http/client/entity/UrlEncodedFormEntity.html) made up of a list of [`BasicNameValuePair`](http://developer.android.com/reference/org/apache/http/message/BasicNameValuePair.html)s. – Yoni Samlan Jun 02 '11 at 20:44
-
2Android has stopped supporting their Apache HttpClient according to [this blog post](http://android-developers.blogspot.com/2011/09/androids-http-clients.html). It'd be nice to have a library that wrapped both and choose which one to use based on the OS version code. – yincrash Sep 28 '12 at 21:53
-
-
Haven't used Retrofit myself yet, but my impression is that they do different things. if you want a drop-in library that does a bit more, integrates JSON parsing for you, supports RxJava idioms out of the box, and don't mind a few extra dependencies, by all means go Retrofit. Volley's a little closer to the metal. – Yoni Samlan Dec 15 '15 at 15:14
-
1Most of the links in this answer are giving 404 errors. Can you please update the links? – Adil Malik Dec 21 '15 at 19:13
Use http-request by Kevin Sawicki. http://kevinsawicki.github.com/http-request/

- 9,553
- 7
- 48
- 66
-
1Very nice and basic, simple to use library. Also has some more advanced features if needed. Such as gzip, caching , http proxy etc. – Zapnologica Aug 15 '13 at 13:01
-
Very nice library, much easier to use than android-async-http. But as good. – Loolooii Jan 14 '15 at 17:22
My favorite one is Ion (complete, under active development). It is built on top of AndroidAsync (to use alone if you don't need Ion features), both by Koushik Dutta.
- Asynchronously download
- Easy to use Fluent API designed for Android
- HTTP POST/PUT
- Transparent usage of HTTP features and optimizations
- View received headers
- Grouping and cancellation of requests
- Download progress callbacks
- Supports file:/, http(s):/, and content:/ URIs
- Request level logging and profiling
- Support for proxy servers like Charles Proxy to do request analysis
- Based on NIO and AndroidAsync
- Ability to use self signed SSL certificates

- 2,110
- 20
- 25
Take a look at http://loopj.com/android-async-http/
Overview says: An asynchronous callback-based Http client for Android built on top of Apache’s HttpClient libraries. All requests are made outside of your app’s main UI thread, but any callback logic will be executed on the same thread as the callback was created using Android’s Handler message passing.
This library was used by popular apps such as Instagram, Pinterest, Heyzap and etc.

- 1,268
- 11
- 10
If you want to use keep alives and gzip and dont want to experience random time out errors unfortunately you cannot simply use one library.
On Android SDK versions below 9 you'll want to use the apache library. On Android SDK versions 9-13 the apache library has issues (random timeouts) and you'll want to use HttpUrlConnection.
Unfortunately in my tests on ICS HttpUrlConnection is really buggy and you'll want to use the Apache library for now.
Official Google Post on the topic: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
Issue i've found on ICS: What android Http Client to use for Ice Cream Sandwich?

- 1
- 1

- 873
- 8
- 19
There is something that I have been doing. It extends loopj library with handlers and loaders that create POJO's. https://github.com/MarkoMilos/android-http

- 25
- 1
- 4
Yep. Its called httpclient, and the javadoc root for it on Android is at http://developer.android.com/reference/org/apache/http/package-summary.html. It does just about everything you want with http, including POST and multipart.

- 64,273
- 8
- 118
- 148
-
I said "robust" I'm looking for a library that builds on these standard API calls to make a post easier. This wheel has been solved many times. – hunterp Jun 01 '11 at 19:16
-
Ah, I wasn't aware they were that hard. Let me know if you find anything. – Femi Jun 01 '11 at 19:18
-
something like this: http://lukencode.com/2010/04/27/calling-web-services-in-android-using-httpclient/ but more robust. – hunterp Jun 01 '11 at 19:23