网络请求框架 Rxjava+ReTrofit+okHttp+MVP

网络请求框架 Rxjava+ReTrofit+okHttp+MVP

Rxjava+ReTrofit+okHttp网络请求框架很火就参考了一些大神的博客加上MVP框架思想写了这一版博客。可能有不合理的地方,敬请指正。

1.Retrofit+Rxjava+okhttp基本使用方法
2.统一处理请求数据格式
3.回调Subscriber处理
4.返回数据的统一判断
5.弱引用管理生命周期,防止泄露
6.MVP框架思想

Rxjava 百度谷歌吧。

ReTrofit基本设置 1.首先确保在AndroidManifest.xml中请求了网络权限 
2.在app/build.gradle添加引用 /okhttp/ compile 'com.squareup.okhttp3:okhttp:3.3.1' compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'

/*rx-android-java*/
compile 'io.reactivex:rxjava:1.1.9'
compile 'io.reactivex:rxandroid:1.2.1'

/*retrofit*/
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'
compile 'com.squareup.retrofit2:retrofit-converters:2.1.0'

/*gson*/
compile 'com.google.code.gson:gson:2.6.2'

okHttp 百度谷歌吧。

本项目用到的测试接口为一个查询IP地址的接口: http://ip.taobao.com/service/getIpInfo.php?ip=63.36.36.36 成功查询到的返回格式为: { "code": 0, "data": { "country": "美国", "country_id": "US", "area": "", "area_id": "", "region": "", "region_id": "", "city": "", "city_id": "", "county": "", "county_id": "", "isp": "", "isp_id": "", "ip": "63.36.36.36" } } 失败情况暂时不考虑,因为这接口不好的地方是失败返回的格式和一般我们的项目写法不一致{"code":1,"data":"invaild ip."} 还是就是本人加上了一个字段message,为了失败成功有个后台返回的统一提示语。

github地址:点击打开链接
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值