Created
March 30, 2016 18:56
-
-
Save lfmingo/768a29eafc4a9d25d75ef31e2be506f7 to your computer and use it in GitHub Desktop.
Add headers in http request using okhttp interceptor with retrofit 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello this code request return ..what is code return it??