1,添加依赖
compile 'com.squareup.retrofit2:retrofit:2.1.0'
//依赖和retrofit对应的gson解析类库,配置了就拥有了json解析的功能
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
2,Retrofit实现简单get使用
-
访问接口文档
【1】定义Api封装url路径
public interface Api {
String SERVER_HOST = "http://192.168.101.78:8080/apitest/";
String TEST = SERVER_HOST+"test";
String LOGIN = SERVER_HOST+"login";
String POST_JSON = SERVER_HOST+"postJson";
String UPLOAD = SERVER_HOST+"upload";
String UPLOAD_MULTI = SERVER_HOST+"uploadMulti";
String IMAGE = SERVER_HOST+"image";
}
【2】定义接口,@