3

I am trying to add header authorization while loading by url img. I tested in postman it works fine , but on mobile device it doesnt work.

Here is the code:

private Picasso getPicasso() { OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.interceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request newRequest = chain.request().newBuilder() .addHeader("Authorization", "Bearer " + userPrefs.accessToken().get()) .build(); return chain.proceed(newRequest); } }); return new Picasso.Builder(getActivity()).downloader(new OkHttpDownloader(okHttpClient)).build(); } 

And how i use it :

getPicasso().load(ServiceGateway.API_BASE_URL + "me/avatar") .networkPolicy(NetworkPolicy.OFFLINE) .into(ivUserImage); 

Gradle:

compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.squareup.okhttp:okhttp:2.5.0' 

What i am doing wrong here ?

3
  • did you checked this link.. ? stackoverflow.com/questions/24273783/… Commented Apr 12, 2016 at 10:12
  • yes didnt work for me Commented Apr 12, 2016 at 10:14
  • Same for me, newRequest was not called at all. Commented Sep 7, 2017 at 2:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.