1.引入对应架包
compile 'com.squareup.retrofit2:retrofit:2.1.0' compile
'com.squareup.retrofit2:converter-gson:2.1.0'
//适配器
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
//RxJava
compile 'io.reactivex:rxjava:1.1.6'
//RxAndroid compile 'io.reactivex:rxandroid:1.2.1'
compile 'com.squareup.okhttp3:okhttp:3.6.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.6.0'
使用:
1. 创建类似请求头的东西,可以公用
String baseUrl = "http://192.168.1.8:8080/RetrofitService/";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.build();
2. 创建请求体, NewsServlet 与baseUrl 拼接 ,get 方法的 传参 Query ,post
public interface NewsService {
//普通call方式
@GET("NewsServlet")
Call<ResponseB