zoukankan      html  css  js  c++  java
  • OkHttp-utils的使用

    1.添加依赖:compile 'com.zhy:okhttputils:2.6.2'


    2.清单文件中注册初始化:
      初始化:OkHttpClient okHttpClient = new OkHttpClient.Builder()
    //                .addInterceptor(new LoggerInterceptor("TAG"))
                    .connectTimeout(10000L, TimeUnit.MILLISECONDS)
                    .readTimeout(10000L, TimeUnit.MILLISECONDS)
                    //其他配置
                    .build();

            OkHttpUtils.initClient(okHttpClient);

    3.okhhtp-utils的get请求:
      OkHttpUtils.get()
                    .url("http://apicloud.mob.com/boxoffice/day/query?key=1d120467e646b&area=CN")
                    .build()
                    .execute(new StringCallback() {
                        @Override
                        public void onError(Call call, Exception e, int id) {
                        }

                        @Override
                        public void onResponse(String response, int id) {
                        }
                    });

    4.okhhtp-utils的post请求:
       OkHttpUtils.post()
                    .url("http://apicloud.mob.com/appstore/horoscope/day")
                    .addParams("date", year1)
                    .addParams("hour", day1)
                    .addParams("key", "1d11949556a24")
                    .build()
                    .execute(new StringCallback() {
                        @Override
                        public void onError(Call call, Exception e, int id) {
                        }

                        @Override
                        public void onResponse(String response, int id) {
                            Log.d("sss", "response:::" + response);
                        }
                    });

    5.okhhtp-utils加载图片:
      OkHttpUtils.get()
                    .url("http://192.168.13.89:8080/Web_server/a.jpg")
                    .build()
                    .execute(new BitmapCallback() {
                        @Override
                        public void onError(Call call, Exception e, int id) {

                        }

                        @Override
                        public void onResponse(Bitmap response, int id) {
                            image.setImageBitmap(response);
                        }
                    });
  • 相关阅读:
    csp-s模拟99题解
    csp-s模拟9697题解
    csps模拟9495凉宫春日的忧郁,漫无止境的八月,简单计算,格式化,真相题解
    csps模拟93序列,二叉搜索树,走路题解
    csps模拟92数列,数对,最小距离题解
    csps模拟8990部分题解
    csps模拟87888990部分题解
    csps模拟86异或,取石子,优化题解
    csps模拟85表达式密码,电压机制,括号密码题解
    csps模拟83最大异或和简单的括号序列旅行计划题解
  • 原文地址:https://www.cnblogs.com/livelihood/p/6758737.html
Copyright © 2011-2022 走看看