Retrofit 2在开发中进行更改多个baseurl
来源:互联网 发布:sql server 2008 sa 编辑:程序博客网 时间:2024/06/16 10:50
多API下的调试,如果每次都改变API然后去重新打包.apk,会比较痛苦,在调试过程中,如果要进行验证API是否成功,可以在运行时改变API达到运行一次验证各API。
/* * Serice生成器 */public class ServiceGenerator { private static String BASE_URL = "http://api.juheapi.com/"; private static Retrofit.Builder builder = new Retrofit.Builder() .addConverterFactory(GsonConverterFactory.create()) .baseUrl(BASE_URL); public static <T> T createServiceFrom(Class<T> serviceClass) { return builder.build().create(serviceClass); }}
在上面这个类里面,进行来添加更改baseurl的代码
public static void changeApiBaseUrl(String newApiBaseUrl) { BASE_URL = newApiBaseUrl; builder = new Retrofit.Builder() .addConverterFactory(GsonConverterFactory.create()) .baseUrl(BASE_URL);}
使用方式:
public void getToh(String key, String version, String month, String day, Callback<Toh> callBack) { mWeChatQuery = ServiceGenerator.createServiceFrom(WeChatQueryService.class); Call<Toh> call = mWeChatQuery.getToh(key,version,month, day); call.enqueue(callBack);}public void getWeChatQuery(String key, Callback<WeChatQuery> callback) { ServiceGenerator.changeApiBaseUrl(ApiAddressPool.API_JUHE_WECHAT);//改变API mWeChatQuery = ServiceGenerator.createServiceFrom(WeChatQueryService.class); Call<WeChatQuery> call = mWeChatQuery.getWeChatQuery(key, "", "", ""); call.enqueue(callback);}
打印结果:
I/System.out: http://api.juheapi.com/I/System.out: http://v.juhe.cn/
阅读全文
1 0
- Retrofit 2在开发中进行更改多个baseurl
- Retrofit解决多个BaseURL切换的问题
- !!!解决Retrofit多BaseUrl及运行时动态改变BaseUrl?
- 在多个模拟器中进行开发
- 使用retrofit做为网络请求时,解决多个BaseURL切换的问题
- Retrofit 2 运行时改变BaseUrl
- ios开发时,在Xcode中添加多个targets进行版本控制
- ios开发时,在Xcode中添加多个targets进行版本控制
- ios开发时,在Xcode中添加多个targets进行版本控制
- ios开发时,在Xcode中添加多个targets进行版本控制
- ios开发时,在Xcode中添加多个targets进行版本控制
- ios开发时,在Xcode中添加多个targets进行版本控制
- ios开发时,在Xcode中添加多个targets进行版本控制
- ios开发时,在Xcode中添加多个targets进行版本控制
- ios开发时,在Xcode中添加多个targets进行版本控制
- ios开发时,在Xcode中添加多个targets进行版本控制
- ios开发时,在Xcode中添加多个targets进行版本控制
- ios开发时,在Xcode中添加多个targets进行版本控制
- (转)正则表达式
- 第二章—C++简单程序设计(一)
- for循环和foreach循环的区别?
- Log4Qt 使用笔记(二)
- ios-app杀死状态下响应推送
- Retrofit 2在开发中进行更改多个baseurl
- Log4Qt使用笔记(三)
- redis5种类型支持的场景
- Nginx 安装部署
- Linux安装Redis,设置密码,使用Java连接
- 微信小程序获取获取openid
- 通过ContentObserver监听数据库某表的增加、删除、更新动作,实现listView异步单项Item的刷新
- Java面试之路(一)Java基础部分
- Maven编译打包过程(clean install)中遇到相关jdk版本导致的问题