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);我使用的是com.squareup.picasso:picasso:2.5.2,com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0,com.squareup.okhttp3:okhttp:3.4.1,它不会发送任何报头。如何解决这个问题?
一旦我添加了这个Picasso.setSingletonInstance(毕加索),后来我使用了毕加索,它就起作用了。
发布于 2017-07-28 15:37:17
试试这个吧。
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);https://stackoverflow.com/questions/45366657
复制相似问题