您的位置:首页 > 理论基础 > 计算机网络

AndroidOkHttp完全解析

2016-07-21 15:43 405 查看

//1. GET

private void getDate() {

OkHttpClient client = new OkHttpClient();
Request build = new Request.Builder().url(url).build();

// 开启异步线程访问网络
Call  call= client.newCall(build);
call.enqueue(new Callback() {
@Override
public void onResponse(Response arg0) throws IOException {

if (arg0.isSuccessful()) {

Log.d("TAGa", arg0.code()+"回执码");
//获取数据的
String b = arg0.body().string();
Log.d("TAG", b.toString());
Toast.makeText(getApplicationContext(), b.toString(),0 ).show();
}
}

@Override
public void onFailure(Request arg0, IOException arg1) {

}
});
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: