Glide - adding header to request

前端 未结 8 1300
北海茫月
北海茫月 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:47

    Since 3.6.0 it's possible to set custom headers for each request:

    GlideUrl glideUrl = new GlideUrl("url", new LazyHeaders.Builder()
        .addHeader("key1", "value")
        .addHeader("key2", new LazyHeaderFactory() {
            @Override
            public String buildHeader() {
                String expensiveAuthHeader = computeExpensiveAuthHeader();
                return expensiveAuthHeader;
            }
        })
        .build());
    
    Glide....load(glideUrl)....;
    

提交回复
热议问题