///< 定义cookie请求 - 采用开源库PersistentCookieJar
OkHttpClient okHttpClient = new OkHttpClient.Builder()
// header添加token等信息
.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request original = chain.request();
Request.Builder requestBuilder = original.newBuilder();
if (!UserInfoManager.getToken().equals("")){
// 添加/更新替换
requestBuilder.header("access-token", UserInfoManager.getToken());
}
if (UserInfoManager.getCityID() > -1){
// 添加/更新替换
requestBuilder.header("city-id", "" + UserInfoManager.getCityID());
}
requestBuilder.header("platform", "app_android");
Request request = requestBuilder.build();
return chain.proceed(request);
}
})
.cookieJar(cookieJar)
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.build();
![132109c7a9881806dae73cdf531a5c7d.png](https://i-blog.csdnimg.cn/blog_migrate/4aa89fa6098ad5380caafa0e403343e7.jpeg)
关注下图片部分就行....