项目介绍
配置
般来说,只需要添加第一个okgo的核心包即可,其余的三个库根据自己的需要选择添加!!!
//必须使用
compile ‘com.lzy.net:okgo:3.0.4‘
//以下三个选择添加,okrx和okrx2不能同时使用
compile ‘com.lzy.net:okrx:1.0.2‘
compile ‘com.lzy.net:okrx2:2.0.2‘
compile ‘com.lzy.net:okserver:2.0.5‘
基本get和post请求
get请求:
OkGo.get("https://api.github.com/repos/square/retrofit/contributors") // 请求方式和请求url
.tag(this) // 请求的 tag, 主要用于取消对应的请求
.cacheKey("cacheKey") // 设置当前请求的缓存key,建议每个不同功能的请求设置一个
.cacheMode(CacheMode.NO_CACHE) // 缓存模式,详细请看缓存介绍
// .cacheTime(3000)//缓存时间
.execute(new StringCallback() {
@Override
public void onSuccess(Response response) {
Log.i("get",response.body());
tvText.setText(response.body());
}
@Override
pub