Persistent cookie storage: saves the cookie to your application's SharedPreferences.2.Installation & Basic Usage(Installation and basic usage)Download the latest. jar file from github and place it in your Android app'slibs/
Folder.
Download the latest jar file from github and place it in the libs/folder of your Android application.
2.1 Download Method:
1. Download from http://loopj.com/android-async-http/
Click DownLoad to DownLoad the latest jar file.
2. Download from https://github.com/loopj/android-async-http.
Find DownLoad ZIP to DownLoad the file. The decompressed directory is as follows:
Examples: A simple example is provided. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + release/uxL + release/release + z8LD5rXEzsS8/r + release + tcRqYXLOxLz + release/CvM/CvLS/release vcD4KPHA + release = "brush: java; "> import com.loopj.android.http.*;
Create a newAsyncHttpClient
Instance and make a request:
AsyncHttpClient client = new AsyncHttpClient();client.get("http://www.google.com", new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { System.out.println(response); }});
Adding GET/POST ParametersRequestParams
TheRequestParams
Class is used to add optional GET or POST parameters to your requests.RequestParams
Can be built and constructed in various ways:
Create emptyRequestParams
And immediately add some parameters:
RequestParams params = new RequestParams();params.put("key", "value");params.put("more", "data");
CreateRequestParams
For a single parameter:
RequestParams params = new RequestParams("single", "value");
CreateRequestParams
From an existingMap
Of key/value strings:
HashMap
paramMap = new HashMap
();paramMap.put("key", "value");RequestParams params = new RequestParams(paramMap);
See the RequestParams Javadoc for more information.
AddInputStream
ToRequestParams
To upload:
InputStream myInputStream = blah;RequestParams params = new RequestParams();params.put("secret_passwords", myInputStream, "passwords.txt");
AddFile
Object toRequestParams
To upload:
File myFile = new File("/path/to/file.png");RequestParams params = new RequestParams();try { params.put("profile_picture", myFile);} catch(FileNotFoundException e) {}
Add a byte array toRequestParams
To upload:
byte[] myByteArray = blah;RequestParams params = new RequestParams();params.put("soundtrack", new ByteArrayInputStream(myByteArray), "she-wolf.mp3");
See the RequestParams Javadoc for more information.
Downloading Binary DataBinaryHttpResponseHandler
TheBinaryHttpResponseHandler
Class can be used to fetch binary data such as images and other files. For example:
AsyncHttpClient client = new AsyncHttpClient();String[] allowedContentTypes = new String[] { "image/png", "image/jpeg" };client.get("http://example.com/file.png", new BinaryHttpResponseHandler(allowedContentTypes) { @Override public void onSuccess(byte[] fileData) { // Do something with the file }});
See the BinaryHttpResponseHandler Javadoc for more information.