public class OkHttp2 {
private static final OkHttp2 ourInstance = new OkHttp2();
public static OkHttp2 getInstance() {
return ourInstance;
}
public OkHttp2 get(String urlpath){
OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
String method = request.method();
String host = request.url().host();
Log.i("OkHttp2",method+"=="+host);
return chain.proceed(request);
}
}).build();
//联网请求
doHttp();
}
private void doHttp() {
OkHttp1.getInstance().get(url).result(new OkHttp1.HttpLister() {
@Override
public void success(String data) {
List<Bean.DataBean> data1 = new Gson().fromJson(data, Bean.class).getData();
Toast.makeText(MainActivity.this,data1+"",Toast.LENGTH_LONG).show();
}
});
}