从此,网络请求只需两步!!!
in your project build.gradle:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
in your module build.gradle dependencies:
implementation 'com.github.xinpengfei520:Okla:<latest-version>'
在Application中:
OklaClient.getInstance().init(this);
提示:默认已经配置好 HttpDns 域名解析和 https 请求。
Okla.request()
.get(url, new ApiRequestListener() {
@Override
public void onSuccess(String result) {
Log.e("TAG" + i, "success===" + result);
}
@Override
public void onError(String ex) {
Log.e("TAG", "error===" + ex);
}
});
此种方式支持将map键值对传入,内部进行Json序列化转换,只支持简单的数据类型,不支持Value为集合或者数组的情况!
Okla.request()
.post(url, map, new ApiRequestListener() {
@Override
public void onSuccess(String result) {
Log.e("TAG", "success===" + result);
}
@Override
public void onError(String ex) {
Log.e("TAG", "error===" + ex);
}
});
此种方式是为了弥补2.2中的缺陷,使用此种方式可以使用第三方框架,如 Gson 等,现将Post的内容转换为Json串之后再传入请求网络。
Okla.request()
.post(url, postJson, new ApiRequestListener() {
@Override
public void onSuccess(String result) {
Log.e("TAG", "success===" + result);
}
@Override
public void onError(String ex) {
Log.e("TAG", "error===" + ex);
}
});
If you find any bug when using Okla, please report here. Thanks for helping us making better.
- fix some bugs;
- upload jitpack repositories;
- optimized code;
- update on 2018-03-28 add post json overload method.
- release okla 1.0 on 2017-11-29
#okla
-dontwarn com.xpf.http.**
-keep class com.xpf.http.**{*;}
#okhttputils
-dontwarn com.zhy.http.**
-keep class com.zhy.http.**{*;}
#okhttp
-dontwarn okhttp3.**
-keep class okhttp3.**{*;}
#okio
-dontwarn okio.**
-keep class okio.**{*;}
Copyright Copyright (C) 2016 x-sir , Okla Framework Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.