依赖
implementation 'me.luzhuo.java.android:lib_okhttp:1.0.7-SNAPSHOT'
implementation 'com.squareup.okhttp3:okhttp:3.14.9'
使用
try {
OKHttpManager ok = new OKHttpManager(new TokenInterceptor() {
@Override
public String getToken() {
return "adsad";
}
});
String url = "http://www.baidu.com";
// String message_get = ok.get(url);
ok.get(url, new IContentCallback() {
@Override
public void onSuccess(int code, String data) {
Log.e(TAG, "<<<" + data);
}
@Override
public void onError(int code, String error) {
Toast.makeText(MainActivity.this, "网络异常, 请检查网络!", Toast.LENGTH_SHORT).show();
}
});
// String message_post = ok.post(url, "{}", PostType.JSON);
ok.post(url, "{}", PostType.JSON, new IContentCallback() {
@Override
public void onSuccess(int i, String data) {
Log.e(TAG, ">>>" + data);
}
@Override
public void onError(int i, String error) {
Toast.makeText(MainActivity.this, "网络异常, 请检查网络!", Toast.LENGTH_SHORT).show();
}
});
// Log.e(TAG, "" + message);
} catch (Exception e) {
e.printStackTrace();
}