1.1 overview(概況)
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(特征)
make asynchronous http requests, handle responses in anonymous
callbacks
進行異步http請求,處理響應在匿名回調中完成
http requests happen outside the ui thread
http請求發生在ui線程之外
requests use a threadpool to cap concurrent resource usage
請求使用threadpool,限制并發資源使用情況
get/post params builder (requestparams)
get / post參數建構使用(requestparams)
multipart file uploads with no additional third party libraries
multipart 檔案上傳,沒有額外的第三方庫
tiny size overhead to your application, only 25kb for everything
在你的應用程式上利用很小的開銷,僅僅25 kb就可以做一切
automatic smart request retries optimized for spotty mobile connections
自動智能請求重試,優化了品質不一的移動連接配接
automatic gzip response decoding support for super-fast requests
自動解碼支援gzip反應速度超快的請求
binary file (images etc) downloading with <code>binaryhttpresponsehandler</code>
<code>二進制檔案(圖檔等)的下載下傳,使用binaryhttpresponsehandler</code>
built-in response parsing into json with <code>jsonhttpresponsehandler</code>
<code>内置響應解析成json,使用jsonhttpresponsehandler</code>
persistent cookie store, saves cookies into your app’s sharedpreferences
持久化cookie存儲,儲存cookie到你的應用程式的sharedpreferences
2.installation
& basic usage(安裝和基本用法)
download the latest .jar file from github and place it in your android app’s <code>libs/</code> folder.
從github上下載下傳最新的最新的jar檔案.并将其放置在你的android應用程式的libs /檔案夾.
2.1下載下傳方式:
點選download即可下載下傳最新的jar檔案
找到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 <code>asynchttpclient</code> instance and make a request:
adding get/post parameters with <code>requestparams</code>
the <code>requestparams</code> class is used to add optional get or post parameters to your requests.<code>requestparams</code> can
be built and constructed in various ways:
create empty <code>requestparams</code> and immediately add some parameters:
create <code>requestparams</code> for a single parameter:
create <code>requestparams</code> from an existing <code>map</code> of
key/value strings:
add an <code>inputstream</code> to the <code>requestparams</code> to
upload:
add a <code>file</code> object to the <code>requestparams</code> to
add a byte array to the <code>requestparams</code> to upload:
downloading binary data with <code>binaryhttpresponsehandler</code>
the <code>binaryhttpresponsehandler</code> class can be used to fetch binary data such as images and other files. for example: