final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Interceptor.Chain chain) throws IOException {
Request.Builder ongoing = chain.request().newBuilder();
ongoing.addHeader("Cache-Control", "no-cache");
ongoing.addHeader("User-Agent", System.getProperty("http.agent"));
ongoing.addHeader("authorization", sharedPreferences.getString("api_key",""));
return chain.proceed(ongoing.build());
}
})
.build();
new Picasso.Builder(mContext).downloader(new OkHttp3Downloader(okHttpClient)).build().with(mContext).load(event.getPictureUrl()).into(holder.eventimage);
I am using
com.squareup.picasso:picasso:2.5.2
,com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0
, com.squareup.okhttp3:okhttp:3.4.1
and its not sending anything in the headers. How to solve this issue?
Once I added this Picasso.setSingletonInstance(picasso); And I used Picasso later on it worked.
Try this one.
Request getRequest = chain.request();
Request.Builder requestBuilder = getRequest.newBuilder()
.addHeader("Cache-Control", "no-cache")
.addHeader("User-Agent", System.getProperty("http.agent"))
.addHeader("authorization", sharedPreferences.getString("api_key",""));
Request request = requestBuilder.build();
return chain.proceed(request);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With