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

通过Interceptor动态添加参数的改怎么处理 #13

Closed
gzsll opened this issue Jan 23, 2018 · 4 comments
Closed

通过Interceptor动态添加参数的改怎么处理 #13

gzsll opened this issue Jan 23, 2018 · 4 comments
Labels

Comments

@gzsll
Copy link

gzsll commented Jan 23, 2018

RT,如果每个请求我会通过Interceptor添加Token,然后获取到的cache time就都是0了,这种情况改怎么处理

@yale8848
Copy link
Owner

请帖上代码看看

@gzsll
Copy link
Author

gzsll commented Jan 24, 2018

@OverRide
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
// Add access_token parameter if user login
UserInfo userInfo = mFRVAccountManager.getUserInfo();
String accessToken = userInfo != null ? userInfo.token() : null;
HttpUrl originalUrl = request.url();
if (!TextUtils.isEmpty(accessToken) && originalUrl != null && TextUtils.isEmpty(originalUrl.queryParameter("access_token"))) {
HttpUrl url = originalUrl.newBuilder().addEncodedQueryParameter("access_token", accessToken).build();
request = request.newBuilder().url(url).build();
}
return chain.proceed(request);
}
通过intercept添加access_token

@yale8848
Copy link
Owner

你自己给url添加新的字段,导致原始请求url链接发生变化,最后找不到这个新的链接,cache time就成默认值了;
我下版本再想办法兼容处理一下这个问题

@yale8848
Copy link
Owner

yale8848 commented Feb 3, 2018

请更新至1.0.7
RetrofitCache.getInstance().addIgnoreParam("access_token");

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

No branches or pull requests

2 participants