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);
                        }
                    });
  • 相关阅读:
    《Dotnet9》系列-开源C# WPF控件库强力推荐
    《Dotnet9》系列-开源C# WPF控件库3《HandyControl》强力推荐
    《Dotnet9》系列-开源C# WPF控件库2《Panuon.UI.Silver》强力推荐
    《Dotnet9》系列-开源C# WPF控件库1《MaterialDesignInXAML》强力推荐
    《Dotnet9》系列-FluentValidation在C# WPF中的应用
    《Dotnet9》建站-本站使用的什么主题?
    结对作业——第二次作业
    团队第一次作业——团队展示
    结队项目——第一次作业
    软件工程实践2017第二次作业
  • 原文地址:https://www.cnblogs.com/livelihood/p/6758737.html
Copyright © 2011-2022 走看看