I've tried several solutions on SO but none worked for me.
How to add a custom HTTP header in android Picasso library version 2.5.2?
Based on Android Picasso library, How to add authentication headers?
I've solved in this way
dependencies:
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp:okhttp:2.5.0'
Code
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.interceptors().add(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request newRequest = chain.request().newBuilder()
.addHeader("X-CUSTOM-HEADER", "my-header-value")
.build();
return chain.proceed(newRequest);
}
});
return new Picasso.Builder(context).downloader(new OkHttpDownloader(okHttpClient)).build();
Thanks for help
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