Unexpected end of stream on okhttp3

妖精的绣舞 提交于 2019-12-09 05:59:40

问题


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

回答1:


instead of

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

try

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


来源:https://stackoverflow.com/questions/37589243/unexpected-end-of-stream-on-okhttp3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!