要引入okhttp.jar
private void HttpResponse(String url, final TextView textView) {
OkHttpClient client = new OkHttpClient();
Request request = new Request
.Builder()
.url(url)//要访问的链接
.build();
Call call = client.newCall(request);
call.enqueue(new okhttp3.Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, okhttp3.Response response) throws IOException {
String res = response.body().string();
//Log.i("response===========>",res);
if (textView == null) {
//Mtoast40(res);//这里我是交给handler处理字符串的比如json,或者土司显示
} else {
textView.setText(res);
}
}
});
}