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 {
    
                }
            });
  • 相关阅读:
    linux指令大全
    strcpy.strcmp.strlen.strcat函数的实现
    推箱子
    头文件string.h里的函数
    SVN 版本控制工具
    Nodejs 学习
    JavaScript基础知识复习
    CSS3 学习小结
    JSP中 JSTL
    JSP中的EL语言
  • 原文地址:https://www.cnblogs.com/Jax/p/5821667.html
Copyright © 2011-2022 走看看