Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Retrofit2 interceptor to add headers to HTTP requests
public class AddHeaderInterceptor implements Interceptor {
public Response intercept(Chain chain) throws IOException {
Request.Builder builder = chain.request().newBuilder();
builder.addHeader("Authorization", "headerContent");
return chain.proceed(;
Copy link

voghDev commented Aug 11, 2016


    OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
    httpClient.addNetworkInterceptor(new AddHeaderInterceptor());
    httpClient.addInterceptor(new LogJsonInterceptor());
    Retrofit retrofit = new Retrofit.Builder()

Copy link

soonsam123 commented Aug 21, 2018

What is the difference between addNetworkInterpector() and addInterceptor() ?

Copy link

psiska commented Aug 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment