Retorfit 的使用
Retorfit:封装类:
public class Retorfit {
private static Retrofit retrofit;
public static RequestAPI getApiService() {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(UrlConstant.baseURL)
.client(RedBookApplication.getOkHttpClient())
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit.create(RequestAPI.class);
}
// public static RequestAPI getApiService2() {
// if (retrofit == null) {
// retrofit = new Retrofit.Builder()
// .baseUrl("http://47.94.151.144/")
// .client(PaperaApplication.getOkHttpClient())
// .addConverterFactory(DecodeConverterFactory.create())
// .build();
// }
// return retrofit.create(RequestAPI.class);
//
// }
}
API类:
public interface RequestAPI {
//阿里云基础数据
@Headers({"Content-Type: application/json", "Accept: application/json"})//需要添加头
@POST
Call<ALiYunBenaJIChuClass> getALiYunJiChuBean(@Header("token") String token, @Url String url, @Body RequestBody requestBody);
最后调用接口通讯类即可:
ublic interface UrlConstant {
// String baseURL="http://192.168.1.39:9090/";//广岳测试
// String baseURL="http://192.168.1.212:9090/";//于辉测试
// String baseURL="https://api.app.azxhs.qd-weimob.com/";//正式
String baseURL="https://api.app.xiaohongshu.qd-weimob.com/";//正式
String WebBaseURL="https://api.app.azxhs.qd-weimob.com/";//正式地址

浙公网安备 33010602011771号