使用url查看图像时将标头传递给Picasso-Android [英] Passing header to Picasso while viewing the image using url - Android
本文介绍了使用url查看图像时将标头传递给Picasso-Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试使用毕加索显示图像时,我需要传递标题.
I need to pass a header when I try to show a image using Picasso.
任何人都可以建议在查看图像时如何向毕加索添加页眉.
Can any one suggest how to add header to picasso while viewing the image.
推荐答案
您可以为此使用downloader
:
https://github.com/JakeWharton/picasso2-okhttp3-downloader
示例:
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request newRequest = chain.request().newBuilder()
.addHeader("custom-header", "custom-header-value")
.build();
return chain.proceed(newRequest);
}
})
.build();
Picasso picasso = new Picasso.Builder(context)
.downloader(new OkHttp3Downloader(client))
.build();
请记住,如果您已经在使用OkHttpClient
,则应该使用该实例或使用client.newBuilder()
创建一个新实例.这样,两个实例将使用相同的请求队列.
Keep in mind that if you are using OkHttpClient
already, you should use that instance or create new one using client.newBuilder()
. This way, both instances will be using the same request queue.
这篇关于使用url查看图像时将标头传递给Picasso-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文