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(;

This comment has been minimized.

Copy link
Owner Author

@voghDev voghDev commented Aug 11, 2016


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

This comment has been minimized.

Copy link

@soonsam123 soonsam123 commented Aug 21, 2018

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


This comment has been minimized.

Copy link

@psiska psiska commented Aug 22, 2018

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