android-async-http开源项目可以是我们轻松的获取网络数据或者向服务器发送数据,使用起来非常简单,关于android-async-http开源项目的介绍内容来自于官方:http://loopj.com/android-async-http/.下面我对此主页上内容进行大体上的翻译,希望能够对你理解android-async-http开源项目有所帮助
1.1 Overview(概况)
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.
译文:
异步基于回调的Http客户端为Android构建,是基于Apache HttpClient库的。所有的请求都是位于应用程序主线程 UI 之外,但任何回调逻辑将相同的线程上执行回调,使用Android的处理程序创建消息传递。
1.2 Features(特征)
BinaryHttpResponseHandler
二进制文件(图片等)的下载,使用BinaryHttpResponseHandler
JsonHttpResponseHandler
内置响应解析成JSON,使用JsonHttpResponseHandler
Download the latest .jar file from github and place it in your Android app’s libs/
folder.
从github上下载最新的最新的jar文件.并将其放置在你的Android应用程序的libs /文件夹.
2.1下载方式:
1.从http://loopj.com/android-async-http/的页面下载
点击DownLoad即可下载最新的jar文件
2.从https://github.com/loopj/android-async-http的页面下载
找到DownLoad ZIP进行下载文件,解压后的目录如下
examples:里面有简单的例子
library:里面存放的是android-async-http开源项目的源码(方法一:可以把library\src\main\java文件下面的文件拷贝到,你应用的src下也可以直接使用)
releases:里面存放的是各个版本的jar文件,(方法二:只需把最新的jar文件拷贝到你应用的libs目录下即可.)
samples:里面存放的也是例子(可供参考)
备注:方法一和方法二只能采用其中之一,建议采用方法二
2.2使用方法
Import the http package.
Create a new AsyncHttpClient
instance and make a request:
Adding GET/POST Parameters with RequestParams
The RequestParams
class is used to add optional GET or POST parameters to your requests.RequestParams
can be built and constructed in various ways:
Create empty RequestParams
and immediately add some parameters:
Create RequestParams
for a single parameter:
Create RequestParams
from an existing Map
of key/value strings:
See the RequestParams Javadoc for more information.
Add an InputStream
to the RequestParams
to upload:
Add a File
object to the RequestParams
to upload:
Add a byte array to the RequestParams
to upload:
See the RequestParams Javadoc for more information.
Downloading Binary Data with BinaryHttpResponseHandler
The BinaryHttpResponseHandler
class can be used to fetch binary data such as images and other files. For example:
See the BinaryHttpResponseHandler Javadoc for more information.