本文介绍了okhttp3上的流意外结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已按照以下链接刷新访问令牌.在将身份验证器添加到okHttp时,从翻新的 onFailure 方法
I had followed this link to refresh access token. While adding Authenticator to okHttp getting error of Unexpected end of stream on okhttp3 from retrofit call back onFailure 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();
尝试
retrofit2.Response<UserLogin> tokenResponse = call.execute();
这篇关于okhttp3上的流意外结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!