首页 > 代码库 > okhttp

okhttp

 /*  // final Request request = new Request.Builder().url("https://localhost:8080/zb.json").build();//这个地址拿不到数据
final Request request = new Request.Builder().url("http://202.192.134.11:8080/zb.json").build();
// final Request request = new Request.Builder().url("https://www.baidu.com").build();
OkHttpClient client = new OkHttpClient();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e("TAG","okhttp获取数据失败");
}

*//**
* 此时还在非UI线程中
* @param call
* @param response
* @throws IOException
*//*
@Override
public void onResponse(Call call, Response response) throws IOException {
final String res = response.body().string();
Log.e("TAG",res);
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.e("TAG", res);
Log.e("TAG", "倪伟金");
version_textView.setText(res);
}
});
}
});
*/

okhttp