Android
- 3 ответа
- 0 вопросов
4
Вклад в тег
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.addInterceptor(new Interceptor() {
@Override
public Response intercept(@NonNull Chain chain) throws IOException {
Request original = chain.request();
String token = ""; // Get token from prefs
if (!TextUtils.isEmpty(token)) {
Request.Builder requestBuilder = original.newBuilder()
.addHeader("Token", token);
Request request = requestBuilder.build();
return chain.proceed(request);
} else {
return chain.proceed(original);
}
}
});