gpt4 book ai didi

retrofit2 - okhttp3 上的流意外结束

转载 作者:行者123 更新时间:2023-12-04 12:57:32 25 4
gpt4 key购买 nike

我关注了这个 link刷新访问 token 。向 okHttp 添加 Authenticator 时出现 的错误okhttp3 上的流意外结束 从改造回电 onFailure 方法

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();

关于retrofit2 - okhttp3 上的流意外结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37589243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com