Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于glide加载 #375

Open
yudu233 opened this issue Jul 30, 2020 · 2 comments
Open

关于glide加载 #375

yudu233 opened this issue Jul 30, 2020 · 2 comments

Comments

@yudu233
Copy link

yudu233 commented Jul 30, 2020

Bug Description:

通过 GlobalConfigModule.Builder 配置okhttp之后,在拦截器中添加了默认header,导致glide加载图片会有header,图片加载失败。

Bug Log:

D: ┌────── Request ────────────────────────────────────────────────────────────────────────
D: │ URL: https://nim-nosdn.netease.im/MTEyNzQ3NTg=/bmltYV8xODYyNDk3NzEzNF8xNTk2MTA0MTY2MTM4XzFjMzgyNDg0LWFlYjUtNDQ4Ni1hNWU5LWMwMzYyYTA4ZjkzNg==
D: │
D: │ Method: @post
D: │
D: │ Headers:
D: │ ┌ User-Agent: ChuangYeTianXia/1.9.000(Android : 8.0.0)
D: │ ├ Content-Type: application/x-www-form-urlencoded
D: │ ├ Content-Length: 391
D: │ ├ Host: nim-nosdn.netease.im
D: │ ├ Connection: Keep-Alive
D: │ └ Accept-Encoding: gzip
D: │
D: │ Body:
D: │ data=iL+p6Pthk6gXmUFj4qdyia/B06vwcfl9sUoBQ3YWjxV5PPnoQLDertgrBV7nakxBdeJcydxUDeB6
D: │ Hl9YCWM0YY5M93/NBZMppPH53jRLhU/Vb+YSULIDyjL/ZtuL2KRtFQGKbrR9aWlMPjYoC/Qqpv90
D: │ Llyw0YU+mXNmW7x8WDStyEBvoDggA4/AGKefAit04SlSaay3jZaW3WZ9aQR1BilHh/v94KycHXrm
D: │ HQF2mlMI7ELn1bQgcpdfeNy1huYewh0J8gXNF4+Gdo8BmZLGBJ05seajmuSk
D: │ &phone_type=ChuangYeTianXia/1.9.000(Android : 8.0.0)
D: └───────────────────────────────────────────────────────────────────────────────────────

而且不知道为什么是post请求...

通过代码发现GlideConfiguration中
@OverRide
public void registerComponents(@nonnull Context context, @nonnull Glide glide, @nonnull Registry registry) {
//Glide 默认使用 HttpURLConnection 做网络请求,在这切换成 Okhttp 请求
AppComponent appComponent = ArmsUtils.obtainAppComponentFromContext(context);
registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(appComponent.okHttpClient()));
}
使用了appComponent.okHttpClient()。

Others:

目前解决方案是重新创建了类继承AppGlideModule,不再依赖于框架的图片加载,不知道会引起什么问题,顾有此问。

@yudu233
Copy link
Author

yudu233 commented Aug 7, 2020

AppGlideModule 框架已经生成不能存在多个 !
使用LibraryGlideModule 无法使用注解生成,要怎么替换这个配置么

@AlexFugui
Copy link

我比较巧了项目里都是post请求
图片都是get请求,而且都是固定服务器头
所以是判断了如果是get请求,而且请求地址是图片服务器的,就不添加header

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants