Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Add headers in http request using okhttp interceptor with retrofit 2
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(new Interceptor() {
public Response intercept(Interceptor.Chain chain) throws IOException {
Request original = chain.request();
Request request = original.newBuilder()
.header("User-Agent", "Your-App-Name")
.header("Accept", "application/vnd.yourapi.v1.full+json")
.method(original.method(), original.body())
return chain.proceed(request);
OkHttpClient client =;
Retrofit retrofit = new Retrofit.Builder()
Copy link

anos19 commented Dec 9, 2020

hello this code request return ..what is code return it??

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