Boss拦截模版
来源:互联网 发布:surface windows rt 编辑:程序博客网 时间:2024/05/14 19:53
拦截器:
public class MyInterceptor implements Interceptor {
@Overridepublic Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Request newRequest = chain.request().newBuilder()
.addHeader("source", "android")
.url(request.url())
.build();
return chain.proceed(newRequest);
}
}
Gson:
public class GsonUtils {
private static Gson instance;
private GsonUtils() {
}
public static Gson getInstance() {
if (instance == null) {
instance = new Gson();
}
return instance;
}
}
OK:
public class OkHttpUtils {
private static volatile OkHttpUtils instance;
private OkHttpClient client;
private Handler handler = new Handler();
private OkHttpUtils() {
client = new OkHttpClient.Builder()
.addInterceptor(new MyInterceptor())
.build();
}
public static OkHttpUtils getInstance() {
if (null == instance) {
synchronized (OkHttpUtils.class) {
if (instance == null) {
instance = new OkHttpUtils();
}
}
}
return instance;
}
public void post(String url, Map<String, Object> map, final CallBack callBack, final Class cls) {
FormBody.Builder builder = new FormBody.Builder();
if (map != null && !map.isEmpty()) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
builder.add(entry.getKey(), (String) entry.getValue());
}
}
Request request = new Request.Builder()
.url(url)
.post(builder.build())
.build();
Call call = client.newCall(request);
神略......
}
- Boss拦截模版
- BOSS
- BOSS
- Boss
- 模版:struts.xml配置拦截器
- 拦截器模版附带MVP防止内存泄漏
- BOSS-PARTIAL1
- BOSS-PARTIAL2
- BOSS-PARTIAL3
- BOSS-PARTIAL4
- 中国移动boss
- BOSS系统
- BOSS介绍
- BOSS含义
- 电信BOSS
- BOSS架构
- BOSS系统
- 模版
- 微信小程序支付开发爬坑攻略(支付签名验证失败)
- 滤镜-Color Lookup Table(ColorLUT)技术
- mingw 环境变量设置
- Matlab--intersect
- 表单js提交报错 submit is not a function
- Boss拦截模版
- 小程序服装行业解决方案,微信小程序在服装业中的应用
- BZOJ1293(SCOI2009)[生日礼物]--维护区间
- JAVA类加载器
- 2018年将会改变人工智能的5个大数据趋势
- laravel 自定义常量的方法
- BAT前端框架和工具
- AI就是“大数据+机器学习”?答案是否定的
- JDBC连接MySQL和SQL Server的工具类