使用单例模式返回数据
1.构造私有化 使Client唯一 节省资源

okhttp的封装
2.懒汉模式
okhttp的封装
判断是否为空 为空上锁 在此非判断是否为空 为空New对象 双重锁
3.写对应的方法 例如 get post downLoad upLoad
添加log拦截器
添加token拦截器
intercept:Toaken拦截  httpLoggingInterceptor Log拦截 addInterceptor添加拦截
3个坑:
① Token拦截器加在log拦截器之前 否则不会显示
② ResponseBody.string():只能调用一次 第二次拿不到任何数据
③ 获得请求数据的总长度,有时返回-1,需要设置请求头:”Accept-Encoding”, “identity”

相关文章:

  • 2021-11-21
  • 2021-07-12
  • 2022-12-23
  • 2021-07-12
  • 2022-12-23
  • 2021-12-17
  • 2021-05-05
  • 2021-09-24
猜你喜欢
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-03-31
  • 2021-11-10
  • 2021-08-05
相关资源
相似解决方案