Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Picasso, add custom HTTP header in version 2.5.2 [closed]

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?

like image 784
Manza Avatar asked Mar 10 '16 09:03

Manza


1 Answers

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

like image 160
Manza Avatar answered Sep 18 '22 14:09

Manza