近日retrofit2正式版发布,终于可以愉快的使用retrofit2了。retrofit2是一个android http通讯框架,内部集成了okhttp。RxJava是一个异步执行框架,采用的是发布订阅模式。使用起来可以让代码更简洁。本文将介绍retrofit2 post的使用方法和集成RxAndroid的retrofit2 post方式的使用。
具体原理不多说,下面讲下使用流程吧。
1.配置gradle
//retrofit2相关依赖
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.1.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0'
//rxandroid相关依赖
compile 'io.reactivex:rxandroid:1.1.0'
compile 'io.reactivex:rxjava:1.1.0'
2.定义请求的service接口,举个例子
public interface RestApi {
@FormUrl