Skip to content

Instantly share code, notes, and snippets.

Embed
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() {
@Override
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())
.build();
return chain.proceed(request);
}
}
OkHttpClient client = httpClient.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
@anos19
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