• 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);
                        }
                    });
  • 相关阅读:
    redis 批量删除key
    控制台直接执行sql语句
    item2 快捷键
    mac mamp环境 PHP命令行反应缓慢解决
    composer gitlab 搭建私包
    PostgreSql命令
    maven 程序包com.sun.image.codec.jpeg
    lumen配置日志daily模式
    PHPStorm怎么修改选中的背景颜色呢?
    vim 配置文件.vimrc,高亮+自动缩进+行号+折叠+优化
  • 原文地址:https://www.cnblogs.com/livelihood/p/6758737.html
Copyright © 2020-2023  润新知