开源项目之Android async-http(异步 HTTP 客户端开发包)
来源:互联网 发布:java缓存博客园 编辑:程序博客网 时间:2024/06/06 07:43
AsyncHttpClient 这个类库可以在Java应用程序中执行HTTP 请求并异步处理HTTP响应。用法非常简单。
项目如图:
源码分析:
public class AsyncHttpResponseHandler { //请求返回处理 成功 失败 开始 完成 等自定义的消息
public class BinaryHttpResponseHandler extends AsyncHttpResponseHandler { //字节流返回处理 该库用于处理图片等
public class JsonHttpResponseHandler extends AsyncHttpResponseHandler { //json请求返回处理 服务器与客户端用json交流时使用
class AsyncHttpRequest implements Runnable { //基于线程 异步请求 通过AsyncHttpResponseHandler回调
public class PersistentCookieStore implements CookieStore { //HttpClient处理数据 使用cookie持久性存储接口
public class RequestParams { //封装了参数处理 例如:
* RequestParams params = new RequestParams(); * params.put("username", "james"); * params.put("password", "123456"); * params.put("email", "my@email.com"); * params.put("profile_picture", new File("pic.jpg")); // Upload a File * params.put("profile_picture2", someInputStream); // Upload an InputStream * params.put("profile_picture3", new ByteArrayInputStream(someBytes)); // Upload some bytes * * AsyncHttpClient client = new AsyncHttpClient(); * client.post("http://myendpoint.com", params, responseHandler);class RetryHandler implements HttpRequestRetryHandler {//多个线程同步处理
public class SerializableCookie implements Serializable { //操作cookie 放入/取出数据
class SimpleMultipartEntity implements HttpEntity { //处理多个请求实体封装
public abstract class SyncHttpClient extends AsyncHttpClient { //同步客户端请求
public class AsyncHttpClient { //异步客户端请求 如:
* AsyncHttpClient client = new AsyncHttpClient(); * client.get("http://www.google.com", new AsyncHttpResponseHandler() { * @Override * public void onSuccess(String response) { * System.out.println(response); * } * });
操作实例如:
private static AsyncHttpClient client = new AsyncHttpClient(); public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.get(getAbsoluteUrl(url), params, responseHandler); } public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.post(getAbsoluteUrl(url), params, responseHandler); } private static String getAbsoluteUrl(String relativeUrl) { return BASE_URL + relativeUrl; }
项目下载
- 开源项目之Android async-http(异步 HTTP 客户端开发包)
- android开发步步为营之67:使用android开源项目android-async-http异步下载文件
- 开源项目之Android async-http
- 开源项目之android-async-http开源库
- 关于开源项目android-async-http
- Http请求之android-async-http 异步框架请求
- android-async-http 异步网络请求客户端请求接口
- 详解Android异步请求之 android-async-http开源框架
- android-async-http异步下载
- Android开发之Android-Async-Http
- Android之Async-http
- android-async-http开源项目介绍及使用方法
- android-async-http开源项目介绍及使用方法
- android-async-http开源项目介绍及使用方法
- android-async-http开源项目介绍及使用方法
- android-async-http开源项目介绍及使用方法
- android开发--android-async-http
- Android 开源框架之 Android-async-http 源码解读
- SecurityUtil
- HDU 1008
- 重定向与请求转发
- 1704
- Android拍照、调用系统图库、裁剪图片到指定大小后输出
- 开源项目之Android async-http(异步 HTTP 客户端开发包)
- GPRS 介绍
- StringUtil
- ValidateUtil
- linux新手入门一
- 使用HTML 5捕捉音频与视频信息
- 通过nodejs插入删除MongoDB数据
- 游戏开发笔记(七)——对象系统设计
- JSON传递bool类型数据的处理方式