okhttp3上意外的流结束

时间:2016-06-02 10:27:37

标签: retrofit2 okhttp3

我已按照此link刷新访问令牌。在向okHttp添加Authenticator时,从改装回调 onFailure 方法 onhailp 获取 okhttp3上的意外结束错误

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** 
  }

1 个答案:

答案 0 :(得分:0)

而不是

UserLogin userLogin = call.execute().body();

尝试

retrofit2.Response<UserLogin> tokenResponse = call.execute();