private static final String baseUrl = "";
public static void loadData(final HttpUtilsCallback httpUtilsCallback) {
Request request = new Request.Builder()
.url(baseUrl)
.build();
OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
httpUtilsCallback.callbackErr(e.getMessage());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String string = response.body().string();
Gson gson = new Gson();
TestBean testBean = gson.fromJson(string, TestBean.class);
httpUtilsCallback.callbackOK(testBean);
//回调数据
}
});
}
public static void loadData(final HttpUtilsCallback httpUtilsCallback) {
Request request = new Request.Builder()
.url(baseUrl)
.build();
OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
httpUtilsCallback.callbackErr(e.getMessage());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String string = response.body().string();
Gson gson = new Gson();
TestBean testBean = gson.fromJson(string, TestBean.class);
httpUtilsCallback.callbackOK(testBean);
//回调数据
}
});
}