Glide添加token和userId

方法一:

          GlideUrl glideUrl = new GlideUrl(url, new LazyHeaders.Builder()
                  .addHeader("userId", userId)
                  .addHeader("token", token)
                  .build());

        FutureTarget<File> target = Glide.with(context).asFile().load(glideUrl).submit();

方法二:

public class CustomGlideUrl extends GlideUrl {

    public CustomGlideUrl(String url) {
        super(url, new Headers() {
            @Override
            public Map<String, String> getHeaders() {
                Map<String, String> headers = new HashMap<>();
                String userIndexCode = HiAccountInfo.getUserIndexCode();
                if (!TextUtils.isEmpty(userIndexCode)) {
                    userIndexCode = Base64.encodeToString(userIndexCode.getBytes(), Base64.NO_WRAP);
                } else {
                    userIndexCode = null;
                }
                headers.put("Token", AddressFetcher.getInstance().getShortToken());
                headers.put("userId", userIndexCode);
                return headers;
            }
        });
    }
}
Glide.with(context).asFile().load(new CustomGlideUrl(url)).submit();
上一篇:Leetcode 17. 电话号码的字母组合


下一篇:头歌:SparkSQL简单使用