把请求头设置到拦截器

//在登陆成功的的成功方法里写
LoginEntity.ResultBean list = loginEntity.getResult();
SharedPreferences.Editor edit = login.edit();
edit.putString(“userId”, list.getUserId() + “”);
edit.putString(“sessionId”, list.getSessionId());
edit.commit();
//在app里写

@Override
public void onCreate() {
super.onCreate();
//存user,sessionid
getInstace();

}
private void getInstace() {
    context = getApplicationContext();
}
public static Context getContentInstace() {
    return context;
}

//工具类在拦截器里写
SharedPreferences login = app.getContentInstace().getSharedPreferences(“login”, Context.MODE_PRIVATE);

                    Request request = chain.request();
                    Request.Builder headers = request.newBuilder()
                            .addHeader("userId", login.getString("userId", ""))
                            .addHeader("sessionId", login.getString("sessionId", ""));
                    Request request1 = headers.build();
                    return chain.proceed(request1);

你可能感兴趣的:(把请求头设置到拦截器)