美文网首页
Glide框架添加header请求-Token为例

Glide框架添加header请求-Token为例

作者: maiduoduo | 来源:发表于2020-03-03 16:13 被阅读0次

glide添加header

有时候在项目中,对于安全机制认证,会对所有的接口进行Token认证处理,这里我们就需要在Glide框架请求图片资源的时候,请求逻辑中需要将TokenCookies添加到Header进行资源请求。那么如何运用Glide进行添加Header呢?请往下看


运用Glide框架中自带的GlideUrlLazyHeaders进行Header添加

    GlideUrl glideUrl = new GlideUrl(url, new LazyHeaders.Builder() 
    .addHeader(“token”, mToken) 
    .build()); 


Glide框架正常请求图片,将上段代码获取到的glideUrl添加到.load()方法中即可
    Glide.with(this) 
    .load(glideUrl) 
    .error(R.mipmap.report_im) 
    .into(viewHolderAttr.reort_icon);


亲测Glide的版本

glide-4.8.0
依赖库引入:这里提供glide-4.11.0引入方式

//Or use Gradle:

       repositories {
         mavenCentral()
         google()
       }

       dependencies {
         implementation 'com.github.bumptech.glide:glide:4.11.0'
         annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
       }

//Or Maven:

   <dependency>
     <groupId>com.github.bumptech.glide</groupId>
     <artifactId>glide</artifactId>
     <version>4.11.0</version>
   </dependency>
   <dependency>
     <groupId>com.github.bumptech.glide</groupId>
     <artifactId>compiler</artifactId>
     <version>4.11.0</version>
     <optional>true</optional>
   </dependency>

相关文章

网友评论

      本文标题:Glide框架添加header请求-Token为例

      本文链接:https://www.haomeiwen.com/subject/svyhlhtx.html