Glide - 向请求添加标头 [英] Glide - adding header to request

查看:48
本文介绍了Glide - 向请求添加标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以在下载图像时添加自定义标头以进行请求?我可以在 Glide 中使用 volley 或 okhttp.

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

我尝试向 okhttpclient 中的 cookiemanager 添加 cookie,但没有帮助.

I tried adding a cookie to the cookiemanager in okhttpclient, but it didn't help.

Glide 中是否有调试请求响应的方法?

Is there a method to debug request response in Glide?

推荐答案

自从 3.6.0 可以为每个请求设置自定义标头:

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)....;

这篇关于Glide - 向请求添加标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆