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. You can also use it in Service or background thread, library will automatically recognize in which context is ran.
If you are also looking for a great android crash reporting service, I’d also recommend checking out my company, Bugsnag.
Features
Using upstream HttpClient of version 4.3.6 instead of Android provided DefaultHttpClient
Compatible with Android API 23 and higher
Make asynchronous HTTP requests, handle responses in anonymous callbacks
HTTP requests happen outside the UI thread
Requests use a threadpool to cap concurrent resource usage
GET/POST params builder (RequestParams)
Multipart file uploads with no additional third party libraries
Streamed JSON uploads with no additional libraries
Handling circular and relative redirects
Tiny size overhead to your application, only 90kb for everything
Automatic smart request retries optimized for spotty mobile connections
Automatic gzip response decoding support for super-fast requests
Binary protocol communication with BinaryHttpResponseHandler
Built-in response parsing into JSON with JsonHttpResponseHandler
Saving response directly into file with FileAsyncHttpResponseHandler
Persistent cookie store, saves cookies into your app’s SharedPreferences
Integration with Jackson JSON, Gson or other JSON (de)serializing libraries with BaseJsonHttpResponseHandler
Support for SAX parser with SaxAsyncHttpResponseHandler
Support for languages and content encodings, not just UTF-8
Persistent Cookie Storage with PersistentCookieStore
This library also includes a PersistentCookieStore which is an implementation of the Apache HttpClient CookieStore interface that automatically saves cookies to SharedPreferences storage on the Android device.
This is extremely useful if you want to use cookies to manage authentication sessions, since the user will remain logged in even after closing and re-opening your app.
First, create an instance of AsyncHttpClient:
Now set this client’s cookie store to be a new instance of PersistentCookieStore, constructed with an activity or application context (usually this will suffice):
Any cookies received from servers will now be stored in the persistent cookie store.
To add your own cookies to the store, simply construct a new cookie and call addCookie:
Some requests may need username/password credentials when dealing with API services that use HTTP Basic Access Authentication requests. You can use the method setBasicAuth()to provide your credentials.
Set username/password for any host and realm for a particular request. By default the Authentication Scope is for any host, port and realm.
You can also provide a more specific Authentication Scope (recommended)
You can test the library on real device or emulator using provided Sample Application. Sample application implements all important functions of library, you can use it as source of inspiration.
To build a .jar file from source, first make a clone of the android-async-http github repository. Then you have to have installed Android SDK and Gradle buildscript, then just run:
This will generate a file in path {repository_root}/library/build/libs/library-1.4.9.jar.
Reporting Bugs or Feature Requests
Please report any bugs or feature requests on the github issues page for this project here:
And many others, contributions are listed in each file in license header. You can also find contributors by looking on project commits, issues and pull-requests on Github
License
The Android Asynchronous Http Client is released under the Android-friendly Apache License, Version 2.0. Read the full license here: