OkHttp是一个高效的HTTP客户端,而OkGo是对OkHttp的封装,提供了更加便捷的HTTP请求操作。OkGo的用法如下:
implementation 'com.lzy.net:okgo:3.0.4'
OkGo.getInstance().init(this);
OkGo.get("https://www.example.com/api")
.tag(this)
.params("key", "value")
.execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
String result = response.body();
//处理请求结果
}
});
OkGo.getInstance().cancelTag(this);
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:android中okgo的作用是什么