栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

rxhttp的简单使用(android)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

rxhttp的简单使用(android)

github:liujingxing/rxhttp:  Based on OkHttp encapsulation, support Kotlin Coroutines、RxJava2、RxJava3; 30s to get started. (github.com)https://github.com/liujingxing/rxhttp

简单使用(java)

详细请看github

1、配置jitpack到项目的build.gradle文件中

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

2、添加RxHttp依赖

  dependencies {

    def rxhttp_version = '2.8.7'
    implementation "com.github.liujingxing.rxhttp:rxhttp:$rxhttp_version"
    annotationProcessor "com.github.liujingxing.rxhttp:rxhttp-compiler:$rxhttp_version"


}

3、配置RxJava添加到依赖

implementation 'io.reactivex.rxjava3:rxjava:3.1.4'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation 'com.github.liujingxing.rxlife:rxlife-rxjava3:2.2.2' //管理RxJava3生命周期,页面销毁,关闭请求
annotationProcessor "com.github.liujingxing.rxhttp:rxhttp-compiler:$rxhttp_version"

4、通过javaCompileOptions指定RxHttp相关类包名

android {
    defaultConfig {
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = [
                    rxhttp_package: 'rxhttp',  //指定RxHttp类包名,可随意指定
                ]
            }
        }
    }
}

4、通rebuilt

5、基础get使用

RxHttp.get("http://...")  //第一步,确定请求类型,可以选择postForm、postJson等方法           
    .asString()           //第二步,确定返回类型,这里返回String类型      
    .subscribe(s -> {     //第三步,订阅观察者,第二步返回Observable对象
        //请求成功                                         
    }, throwable -> {                                  
        //请求失败                                         
    });                                                

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/949236.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号