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. From https://github.com/loz? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> vcGovYW5kcm9pZC1hc3luYy1odHRwtcTSs8Pmz8LU2DwvcD4KPHA + pgltzybzcm9" http://www.2cto.com/uploadfile/Collfiles/20140526/2014052609121926.jpg "alt =" \ ">
Find DownLoad ZIP to DownLoad the file. The decompressed directory is as follows:
Examples: A simple example is provided.
Library: contains the source code of the android-async-http open source project (Method 1: You can copy the files under the library \ src \ main \ java file, you can also use the src file directly)
Releases: stores jar files of various versions. (Method 2: copy the latest jar files to the libs directory of your application .)
Samples: stored in it is also an example (for reference)
Note: method 1 and method 2 can only be used. method 2 is recommended.
2.2 usage
Import the http package.
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.