不错的,国人造的一个牛逼的网络请求框架。本人支持国产,也支持洋货。Nohttp做了相对完善的封装,
NoHttp封装了:文件下载、断点续传、304缓存、302/303传参数、传文件、请求头、多文件上传、大文件上传、Cookie自动管理等多种功能,与之前的Volley相比叫,这是Volley而没有的,而且使用Volley需要我们去写很多代码做封装,而NoHttp直接可以用,不需再做二次开发,当然NoHttp的架构设计上是很方便开发做自己的封装的。
Nohttp用来快速快发小项目,还是很受欢迎的。
OkHttp和HttpURLConnection(HttpClient在Android6.0已完全弃用)之间,如果开发者自己封装自己的框架,我推荐OkHttp,这个框架也是Google官方推荐的。理由不在赘述,Google百度一大推。
这是NoHttp作者官方使用的文档,http://doc.nohttp.net/162186
Nohttp简单使用
1,依赖 compile ‘com.yanzhenjie.nohttp:nohttp:1.1.1’
2,初始化配置
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// NoHttp默认初始化。
NoHttp.initialize(this, new NoHttp.Config()
.setConnectTimeout( * ) // 全局连接超时时间,单位毫秒。
.setReadTimeout( * ) // 全局服务器响应超时时间,单位毫秒。
// .setCacheStore(
// new DiskCacheStore(this) // 配置缓存到SD卡。
// )
.setCacheStore(
new DBCacheStore(this) // 配置缓存到数据库。
.setEnable(true) // true启用缓存,fasle禁用缓存。
)
//指定使用OKHttp或者HTTPURLCONNECTION
.setNetworkExecutor(new URLConnectionNetworkExecutor())
);
}
}
Activity
private ProgressDialog dialog;
//看成handle
private OnResponseListener<String> listener = new OnResponseListener<String>() {
@Override
public void onStart(int what) {
//请求开始 所在哪一个线程
//显示滚动框
dialog = ProgressDialog.show(MainActivity.this, "Nohttp", "加载中。。。。。");
}
@Override
public void onSucceed(int what, Response<String> response) {
//请求成功,各个请求刷新UI
switch (what) {
case :
break;
case :
break;
case :
break;
}
}
@Override
public void onFailed(int what, Response<String> response) {
//请求失败
}
@Override
public void onFinish(int what) {
//请求完成
//销毁滚动框
dialog.dismiss();
}
};
//联网方式(GET,POST)
//链接
//参数
//回复处理
Request<String> stringRequest = NoHttp.createStringRequest("http://www.baidu.com/", RequestMethod.GET);
// stringRequest.add();添加请求参数
stringRequest.setPriority(Priority.DEFAULT);//添加优先级
RequestQueue requestQueue = NoHttp.newRequestQueue();
//添加请求队列
requestQueue.add(, stringRequest, listener);
Request<String> stringRequest2 = NoHttp.createStringRequest("http://news.baidu.com/", RequestMethod.POST);
//添加请求队列
requestQueue.add(, stringRequest2, listener);
需要看更详细的,可以看文档哦。

鼎立支持开源精神,支持NoHttp~~
如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续码蛋!