Glide - adding header to request

前端 未结 8 1303
北海茫月
北海茫月 2021-02-02 09:25

is there a method to add custom header to request when image is downloaded? I can use volley or okhttp in Glide.

I try add cookie to cookiemanager in okhttpclient, but i

8条回答
  •  别那么骄傲
    2021-02-02 09:54

    Try this:

    ImageView imgThumb = itemView.findViewById(R.id.image_thumb);
    
    GlideUrl url = new GlideUrl("https://your-url.com", new LazyHeaders.Builder()
                    .addHeader("User-Agent", "your-user-agent")
                    .build());
    
    RequestOptions options = new RequestOptions()
        .diskCacheStrategy(DiskCacheStrategy.NONE);
    
    Glide.with(mContext).load(glideUrl)
                        .transition(withCrossFade())
                        .thumbnail(0.5f)
                        .apply(options)
                        .into(imgThumb);
    

    The Glide reference is:

    implementation 'com.github.bumptech.glide:glide:4.6.1'
    

提交回复
热议问题