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(特征)

  • 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/的页面下载

点击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.

import com.loopj.android.http.*;

Create a new AsyncHttpClient instance and make a request:

AsyncHttpClient client = new AsyncHttpClient();
client.get("http://www.google.com", new AsyncHttpResponseHandler() {@Overridepublic void onSuccess(String response) {System.out.println(response);}
});

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:

RequestParams params = new RequestParams();
params.put("key", "value");
params.put("more", "data");

Create RequestParams for a single parameter:

RequestParams params = new RequestParams("single", "value");

Create RequestParams from an existing Map of 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 InputStream to the RequestParams to upload:

InputStream myInputStream = blah;
RequestParams params = new RequestParams();
params.put("secret_passwords", myInputStream, "passwords.txt");

Add a File object to the RequestParams 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 to the RequestParams 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 Data with BinaryHttpResponseHandler

The BinaryHttpResponseHandler 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) {@Overridepublic void onSuccess(byte[] fileData) {// Do something with the file}
});

See the BinaryHttpResponseHandler Javadoc for more information.

08_android入门_android-async-http开源项目介绍及使用方法相关推荐

  1. windows下nodejs express安装及入门网站,视频资料,开源项目介绍

    windows下nodejs express安装及入门网站,视频资料,开源项目介绍,pm2,supervisor,npm,Pomelo,Grunt安装使用注意事项等总结 第一步:下载安装文件 下载地址 ...

  2. 开源项目介绍 |APIJSON- 后端零代码接口和文档ORM 库

    2021腾讯犀牛鸟开源人才培养计划 开源项目介绍 滑至文末报名参与开源人才培养计划 提交项目Proposal APIJSON项目介绍 标签:后端, ORM 库 技术栈:java APIJSON- 后端 ...

  3. 几种P2P流媒体开源项目介绍

    P2P流媒体开源项目介绍 1. PeerCast 2002年成立,最早的开源P2P流媒体项目.PeerCast把节点按树结构组织起来, 每个频道都是一个树, 直播源是根节点,父节点只给子节点提供数据. ...

  4. 揭开webRTC媒体服务器的神秘面纱——WebRTC媒体服务器开源项目介绍

    揭开webRTC媒体服务器的神秘面纱--WebRTC媒体服务器&开源项目介绍 WebRTC生态系统是非常庞大的.当我第一次尝试理解WebRTC时,网络资源之多让人难以置信.本文针对webRTC ...

  5. php html小项目,使用PHP把HTML生成PDF文件的几个开源项目介绍

    这篇文章主要介绍了使用PHP把HTML生成PDF文件的几个开源项目介绍,本文罗列了FPDF.DomPDF.TCPDF等项目的特点,需要的朋友可以参考下 利用PHP编码生成PDF文件是一个非常耗时的工作 ...

  6. imageJ二次开发之旅 – imageJ开源项目介绍

    imageJ二次开发之旅 – imageJ开源项目介绍 imageJ起源: imageJ项目最初是由NIH(NationalInstitutes of Health,美国国家卫生研究院)在1997发起 ...

  7. P2P流媒体开源项目介绍

    P2P流媒体开源项目介绍 1. PeerCast 2002年成立,最早的开源P2P流媒体项目.PeerCast把节点按树结构组织起来, 每个频道都是一个树, 直播源是根节点,父节点只给子节点提供数据. ...

  8. 【P2P】【转载】P2P流媒体开源项目介绍

    大神的整理 P2P流媒体开源项目介绍 前言: 最近在做一个网站,发现p2p流媒体技术对于解决高流量高带宽问题真的很不错. 据说现在一些视频和直播公司在研究p2p+cdn,证明了p2p永不过时. 先记录 ...

  9. 优秀的 Verilog/FPGA开源项目介绍(七)- CAN通信

    优秀的 Verilog/FPGA开源项目介绍(七)- CAN 0.CAN总线介绍 <[科普]CAN总线介绍及FPGA实现方案简介> 1.CAN权威文档 CAN总线有两个ISO国际标准:IS ...

最新文章

  1. 一文看尽 27 篇 CVPR 2021 2D 目标检测论文
  2. ps -ef |grep 输出的具体含义
  3. PYTHON编码处理-str与Unicode的区别
  4. mysql myasam_MySQL锁(MyISAM和InnoDB)
  5. AT COMMAND的命令集
  6. servlet类中@WebServlet 报错,不变色
  7. leetcode 700 二叉搜索树的搜索
  8. resnext50_32x4d-inference
  9. “scikit-learn(sklearn) 官方文档中文版”
  10. 神奇的G1——Java全新垃圾回收机制
  11. java验证码实现方式,SpringBoot实现后端验证码,CaptchaUtil美观的后端随机、算术、中文动态验证码
  12. 简述冯诺依曼计算机体系结构
  13. matlab排序函数 下标,Matlab自带排序函数sort用法
  14. Excel表格中超链接转图片
  15. VFB直接使用TCP发送电子邮件源码
  16. python机器人编程——差速机器人小车的控制,控制模型、轨迹跟踪,轨迹规划、自动泊车(上)
  17. 【高精度】高精度除以高精度 C++题解
  18. Speedoffice(excel)如何制作斜线表头
  19. 【微信小程序】车位在线销售平台(三)
  20. 【VBScript】MsgBox()函数

热门文章

  1. vue父子组件传值之 $emit和props
  2. 关于浏览器的选择 360浏览器 firefox chrome
  3. 循环冗余校验(CRC)的简单应用实践
  4. MATLAB输入/输出语句
  5. I2C虚拟项目-test3
  6. 梯度消失和梯度爆炸_出现梯度消失与梯度爆炸的原因以及解决方案
  7. 使用FileReader制作一个简短图片上传
  8. juicessh连接树莓派认证失败
  9. 铁甲雄心机器人建造成本_中国农民造机器人花费近百万《铁甲雄心》自制钢铁侠惊艳全场...
  10. 《NFL橄榄球》:新奥尔良圣徒·橄榄1号位