android - OKHttp adding headers -


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 using com.squareup.picasso:picasso:2.5.2 ,com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0, com.squareup.okhttp3:okhttp:3.4.1 , not sending in headers. how solve issue?

once added picasso.setsingletoninstance(picasso); , used picasso later on worked.

try 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); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -