安卓okhttp3 get请求,并更新Ui

public void getContent() throws IOException {
        OkHttpClient client = new OkHttpClient();
        {
            Request request = new Request.Builder().url("https://pv.sohu.com/cityjson")
                    .addHeader("User-Agent", "mozilla").build();
            Call call = client.newCall(request);
            call.enqueue(new Callback() {
                @Override
                public void onFailure(Call call, IOException e) {
                    System.out.println("onFailure: " + e.getMessage());
                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    final String res = response.body().string();
                    System.out.println(res);

                    MainActivity.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            // 更新组件UI
                        }
                    });
                }
            });
        }

    }
-- 展开阅读全文 --
CI框架MySQL一次更新多条记录
« 上一篇 11-11
selenium+ chrome浏览器使用用户名密码验证代理
下一篇 » 12-31

发表评论