android-async-http开源项目介绍及使用方法
2014-08-18 20:15
666 查看
转自:http://www.2cto.com/kf/201405/304133.html
android-async-http开源项目可以是我们轻松的获取网络数据或者向服务器发送数据,使用起来非常简单,关于android-async-http开源项目的介绍内容来自于官方:http://loopj.com/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(特征)
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
Built-in response parsing into JSON with
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
从github上下载最新的最新的jar文件.并将其放置在你的Android应用程序的libs /文件夹.
2.1下载方式:
1.从http://loopj.com/android-async-http/的页面下载
2.从https://github.com/loopj/android-async-http的页面下载
找到DownLoad ZIP进行下载文件,解压
Create a new
instance and make a request:
dding GET/POST Parameters with
The
Create empty
Create
Create
See the RequestParams Javadoc for more information.
Add an
Add a
Add a byte array to the
See the RequestParams Javadoc for more information.
Downloading Binary Data with
The
android-async-http开源项目可以是我们轻松的获取网络数据或者向服务器发送数据,使用起来非常简单,关于android-async-http开源项目的介绍内容来自于官方:http://loopj.com/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(特征)
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
BinaryHttpResponseHandler
二进制文件(图片等)的下载,使用BinaryHttpResponseHandler
Built-in response parsing into JSON with
JsonHttpResponseHandler
内置响应解析成JSON,使用JsonHttpResponseHandler
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
libs/folder.
从github上下载最新的最新的jar文件.并将其放置在你的Android应用程序的libs /文件夹.
2.1下载方式:
1.从http://loopj.com/android-async-http/的页面下载
2.从https://github.com/loopj/android-async-http的页面下载
找到DownLoad ZIP进行下载文件,解压
Create a new
AsyncHttpClient
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); } });
dding GET/POST Parameters with
RequestParams
The
RequestParamsclass is used to add optional GET or POST parameters to your requests.
RequestParamscan be built and constructed in various ways:
Create empty
RequestParamsand immediately add some parameters:
RequestParams params = new RequestParams(); params.put("key", "value"); params.put("more", "data");
Create
RequestParamsfor a single parameter:
RequestParams params = new RequestParams("single", "value");
Create
RequestParamsfrom an existing
Mapof key/value strings:
HashMap<string, string=""> paramMap = new HashMap<string, string="">(); paramMap.put("key", "value"); RequestParams params = new RequestParams(paramMap);
See the RequestParams Javadoc for more information.
Add an
InputStreamto the
RequestParamsto upload:
InputStream myInputStream = blah; RequestParams params = new RequestParams(); params.put("secret_passwords", myInputStream, "passwords.txt");
Add a
Fileobject to the
RequestParamsto 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 to the
RequestParamsto 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 Data with
BinaryHttpResponseHandler
The
BinaryHttpResponseHandlerclass 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.
相关文章推荐
- 08_android入门_android-async-http开源项目介绍及使用方法
- android-async-http开源项目介绍及使用方法
- android-async-http开源项目介绍及使用方法
- android-async-http开源项目介绍及使用方法
- android-async-http开源项目介绍及使用方法
- android开源框架android-async-http详细的使用介绍
- android开发步步为营之67:使用android开源项目android-async-http异步下载文件
- Android核心基础-7.Android 网络通信-2.使用开源项目AsyncHttpClient
- 08_android入门_android-async-http开源项目介绍及用法
- Android 文件上传 使用AsyncHttpClient开源框架
- Android开源框架AsyncHttpClient (android-async-http)使用
- Android开源框架--AsyncHttpClient (android-async-http)使用
- android开源框架android-async-http使用
- android开源框架android-async-http使用
- Android项目:使用pulltorefresh开源项目扩展为下拉刷新上拉加载更多的处理方法,监听listview滚动方向
- Android---利用android-async-http开源项目返回json数据
- 利用android-async-http开源项目实现网络代码查看器
- Android项目:使用pulltorefresh开源项目扩展为下拉刷新上拉加载更多的处理方法,监听listview滚动方向 推荐
- 国内开源项目“C语言正则表达式”——特性、使用方法、正则模式等介绍。
- Android最好用的侧滑栏开源项目SlidingMenu,集成方法与使用