所需依赖 ↓ ↓ ↓
OKHttp 依赖:
implementation("com.squareup.okhttp3:okhttp:4.4.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.4.0") //日志拦截依赖
Retrofit 依赖:
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
RxJava 依赖:
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
转换器 依赖 响应得到的json 转为 javabean
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
RXAndroid 依赖
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
RetrofitUil 初始化:

GET请求
定义接口

//Bean类要实现Serializable序列化接口

工具类中定义请求方法

Activity中调用

网友评论