ccccsky 2017-04-12
本人使用 github 现成封装 modules rxretrofitlibrary
一步步封装 移步 http://blog.csdn.net/wzgiceman/article/details/51939574
专栏 移步 http://blog.csdn.net/column/details/13297.html
该博主 三个 版本的 gitbub 成果:
https://github.com/wzgiceman/RxjavaRetrofitDemo-string-master
https://github.com/wzgiceman/RxjavaRetrofitDemo-master
https://github.com/wzgiceman/Rx-Retrofit
本人使用 RxjavaRetrofitDemo-string-master modules
该 网络请求 包含 缓存功能,包含 重试功能
public class IteyeBlogsApi extends BaseApi { public IteyeBlogsApi(){ setBaseUrl("http://www.iteye.com/"); } @Override public Observable getObservable(Retrofit retrofit) { IteyeGetBlogsService api= retrofit.create(IteyeGetBlogsService.class); return api.getAllBlogs(); } }
public interface IteyeGetBlogsService { @GET("blogs") Observable<String> getAllBlogs(); }
myApi = new IteyeBlogsApi();
manager = new HttpManager(this, this);
case R.id.btn_rx_text_iteye: Log.i("baoyou","myApi ===== start"); manager.doHttpDeal(myApi); break;
结果 测试
2.测试 一个 本地rest 服务
public interface LocalUserRestService { @GET("user/list") Observable<String> getAllUsers(); }
public class LocalUserRestApi extends BaseApi { public LocalUserRestApi(){ setBaseUrl("http://192.168.50.61:8081/rest/rest/"); } @Override public Observable getObservable(Retrofit retrofit) { LocalUserRestService api= retrofit.create(LocalUserRestService.class); return api.getAllUsers(); } }
Log.i("baoyou","userRestApi ===== new start"); userRestApi = new LocalUserRestApi(); Log.i("baoyou","userRestApi ===== new start");
@Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_rx_text_rest_user: Log.i("baoyou","userRestApi ===== start"); manager.doHttpDeal(userRestApi); Log.i("baoyou","userRestApi ===== end"); break;
在兴趣的驱动下,写一个免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信捐助,加入it技术扣扣群),没钱捧个人场,谢谢各位。
谢谢您的赞助,我会做的更好!