• 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);
                        }
                    });
  • 相关阅读:
    没了解这些,测试人也要为降薪做好准备!
    测试之巅—自动化测试!
    自动化测试现状趋势解读,附带近年自动化测试常用工具
    技术大佬:如何最快速度上手接口测试?(一篇文章搞定)
    三个Python自动化测试高效工具的使用总结
    Postman接口测试实战分享,这5个问题你必须得知道!【软件测试工程师经验分享】
    Python实现性能自动化测试的方法【推荐好文】
    md5加密
    python操作数据库
    time模块:时间戳和格式化好的时间表示方法及互相转换方法
  • 原文地址:https://www.cnblogs.com/livelihood/p/6758737.html
Copyright © 2020-2023  润新知