OKHttp网络框架

         
//        创建OkHttpClient对象
        OkHttpClient client = new OkHttpClient.Builder().build();
//        创建Request对象,
//        URLDATA——请求的网址
        Request request = new Request.Builder().url(URLDATA).build();


//        try {
////            同步请求
////        获取响应体
//            Response execute = client.newCall(request).execute();
////            请求回来的数据
//            String string = execute.body().string();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        获取响应体(异步请求)
        client.newCall(request).enqueue(new Callback() {
            @Override
//            响应失败
            public void onFailure(Call call, IOException e) {




            }


            @Override
//            响应成功
            public void onResponse(Call call, Response response) throws IOException {
//                请求到的数据
                String string = response.body().string();
            }
        });

猜你喜欢

转载自blog.csdn.net/qq_41832319/article/details/79545573