I use the following lines of code to add a default header to all my requests sent using Retrofit2:
private static OkHttpClient defaultHttpClient = new OkHttpClient(); static { defaultHttpClient.networkInterceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request().newBuilder() .addHeader("Accept", "Application/JSON").build(); return chain.proceed(request); } }); }
After updating the version to beta-3, I also had to upgrade OkHttp to OkHttp3 (in fact, I just changed the package names from okhttp to okhttp3, the library is included in the modification). After that, I get exceptions from this line:
defaultHttpClient.networkInterceptors().add(new Interceptor());
Called: java.lang.UnsupportedOperationException in java.util.Collections $ UnmodifiableCollection.add (Collections.java:932)
Called: java.lang.ExceptionInInitializerError
What is the problem?
Ashkan Sarlak Jan 24 '16 at 7:57 2016-01-24 07:57
source share