zoukankan      html  css  js  c++  java
  • RxAndroid+Retrofit+MVVM(1)OKHttp

    1)Gradle
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.squareup.okio:okio:1.5.0'

    2)Get
            //创建okHttpClient对象
            OkHttpClient mOkHttpClient = new OkHttpClient();
            //创建一个Request
            final Request request = new Request.Builder()
                    .url("http://www.weather.com.cn/data/sk/101010100.html")
                    .build();
    
            //new call
            Call call = mOkHttpClient.newCall(request);
    
            call.enqueue(new Callback() {
                @Override
                public void onFailure(Request request, IOException e) {
    
                }
    
                @Override
                public void onResponse(Response response) throws IOException {
                    String htmlStr =  response.body().string();
                }
            });


    3)Post

            FormEncodingBuilder builder = new FormEncodingBuilder();
            builder.add("username","baobao");
    
            String url = "";
    
            Request request = new Request.Builder()
                    .url(url)
                    .post(builder.build())
                    .build();
    
            OkHttpClient mOkHttpClient = new OkHttpClient();
            mOkHttpClient.newCall(request).enqueue(new Callback(){
                @Override
                public void onFailure(Request request, IOException e) {
    
                }
    
                @Override
                public void onResponse(Response response) throws IOException {
    
                }
            });
  • 相关阅读:
    SCAU 9504 面试
    SCAU 9503 懒人选座位
    SCAU 8628 相亲
    SCAU 10691 ACM 光环
    SCAU 8626 原子量计数
    SCAU 10674 等差对
    HDU ACM 1048 The Hardest Problem Ever (水题)
    SCAU 9502 ARDF
    SCAU 10686 DeathGod不知道的事情
    SCAU 8629 热身游戏(高精度)
  • 原文地址:https://www.cnblogs.com/Jax/p/5821667.html
Copyright © 2011-2022 走看看