首先导入依赖:
RxJava:原理 基于 一种扩展的观察者模式
被观察者 (Observable) 通过 订阅(Subscribe) 按顺序发送事件 给观察者 (Observer), 观察者(Observer) 按顺序接收事件 以及作出对应的响应动作
implementation'io.reactivex.rxjava2:rxjava:2.2.8'
implementation'io.reactivex.rxjava2:rxandroid:2.1.0'
Retrofit:
Retrofit 是一个 Restful 的 http 网络请求框架的封装,网络请求的工作本质上是 Okhttp 完成,而 Retrofit 仅负责 网络请求接口的封装
//Retrofit依赖
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
//Gson converter gson解析
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
//RxJava2 Adapter
implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
/okhttp
implementation 'com.squareup.okhttp3:okhttp:3.4.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
下面开始做一个Get的网络请求:<