android litehttp jar,LiteHttp极简且智能的Android HTTP框架

今天接触到了LiteHttp框架,觉得挺不错,比Vollery更轻量级。详细介绍和用法,请参考:

http://www.eoeandroid.com/thread-326584-1-1.html

上面有详细的介绍,这里简单介绍一下怎么用这个框架来给服务端发送请求,完成客户端用户名和密码的验证。

GitHub链接:

https://github.com/litesuits/android-lite-async

1. 用上面的连接下载相应的liteHttp.jar, 在项目中引用它(Eclipse和Andriod Studio的引用方法不一样,请分别处理)。

2. 初始化

Liteclient = LiteHttpClient.newApacheHttpClient(context);

HttpAsyncExecutor asyncExecutor = HttpAsyncExecutor.newInstance(client);

3. 发送请求,这里会给服务端发送一个验证的loginUrl, 后面会带上用户名和密码, 然后服务端(前提是服务端的接口已经OK)会返回一个Json串(包括Authorize和Version两个属性),ApiLoginReturn这个对象就定义了服务端返回Json串中的属性(Authorize, Version)。当验证成功后,这个框架会自动解析服务端返回的Json串,然后将返回的值自动封装在ApiLoginReturn对象中,这样就能根据ApiLoginReturn对象中Authorize的返回值来验证用户名和密码是否正确。验证成功和失败都有相应的回调函数,能够根据不同的场景做不同的逻辑处理。

asyncExecutor.execute(new Request(loginUrl), new HttpModelHandler() {

@Override

protected void onSuccess(ApiLoginReturn o, Response response) {

if (o.Authorize) {

Toast.makeText(context, "验证成功", Toast.LENGTH_LONG).show();

} else {

Toast.makeText(context, "验证失败", Toast.LENGTH_LONG).show();

}

}

@Override

protected void onFailure(HttpException e, Response response) {

Toast.makeText(context, "验证连接失败,请检查网络连接情况", Toast.LENGTH_LONG).show();

}

});

public static class ApiLoginReturn {

public boolean Authorize; //验证结果

public String Version; //版本号

}

其他的一些功能,比如多文件上传功能,可以参考上面的帖子。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Asynchronous Http Client for Android Build Status An asynchronous, callback-based Http client for Android built on top of Apache's HttpClient libraries. Changelog See what is new in version 1.4.9 released on 19th September 2015 https://github.com/loopj/android-async-http/blob/1.4.9/CHANGELOG.md Javadoc Latest Javadoc for 1.4.9 release are available here (also included in Maven repository): https://loopj.com/android-async-http/doc/ Features Make asynchronous HTTP requests, handle responses in anonymous callbacks HTTP requests happen outside the UI thread Requests use a threadpool to cap concurrent resource usage GET/POST params builder (RequestParams) Multipart file uploads with no additional third party libraries Tiny size overhead to your application, only 60kb for everything Automatic smart request retries optimized for spotty mobile connections Automatic gzip response decoding support for super-fast requests Optional built-in response parsing into JSON (JsonHttpResponseHandler) Optional persistent cookie store, saves cookies into your app's SharedPreferences Examples For inspiration and testing on device we've provided Sample Application. See individual samples here on Github To run Sample application, simply clone the repository and run this command, to install it on connected device gradle :sample:installDebug Maven You can now integrate this library in your project via Maven. There are available two kind of builds. releases, maven central https://repo1.maven.org/maven2/com/loopj/android/android-async-http/ Maven URL: https://repo1.maven.org/maven2/ GroupId: com.loopj.android ArtifactId: android-async-http Version: 1.4.9 Packaging: JAR or AAR Gradle repositories { maven { mavenCentral() } } dependencies { compile 'com.loopj.android:android-async-http:1.4.9' } development snapshots https://oss.sonatype.org/content/repositories/snapshots/com/loopj/android/android-async-http/ Maven URL: https://oss.sonatype.org/content/repositories/snapshots/ GroupId: com.loopj.android ArtifactId: android-async-http Version: 1.5.0-SNAPSHOT Packaging: JAR or AAR Gradle repositories { maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } } dependencies { compile 'com.loopj.android:android-async-http:1.5.0-SNAPSHOT' } Documentation, Features and Examples Full details and documentation can be found on the project page here: https://loopj.com/android-async-http/

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值