我已经遵循了这个link https://stackoverflow.com/questions/35238894/android-retrofit-2-authenticator-result刷新访问令牌。将 Authenticator 添加到 okHttp 时出现错误okhttp3 上的流意外结束从改造回调失败时 method
public class TokenAuthenticator implements Authenticator {
AccessTokenRefreshModel accessTokenRefreshModel = null;
@Override
public Request authenticate(Route route, Response response) throws IOException {
Call<UserLogin> call = iService.refreshAccessToken(BuildConfig.CLIENT_ID, refreshToken);
UserLogin userLogin = call.execute().body();
// Add new header to rejected request and retry it
return response.request().newBuilder()
.header(AUTHORIZATION, userLogin.getAccessToken())
.build();
}
}
Call<User> call = iService.createuser(user);
call.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
}
@Override
public void onFailure(Call<User> call, Throwable t) {
//**Unexpected end of stream on okhttp3**
}
代替
UserLogin userLogin = call.execute().body();
try
retrofit2.Response<UserLogin> tokenResponse = call.execute();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)