RefreshToken 过期后请求挂起 JsonHttpClient ServiceStack [英] Request hangs after RefreshToken expires JsonHttpClient ServiceStack
问题描述
我在 Xamarin.Forms 移动应用中使用 ServiceStack JsonHttpClient 客户端 (5.9.0).
客户端设置如下:
client = new JsonHttpClient(App.BaseEndpoint){RefreshToken = RefreshToken,};var httpClient = client.GetHttpClient();httpClient.Timeout = new TimeSpan(0, timeout, 0);
不记名令牌的刷新工作完美,但刷新令牌过期后,请求只是挂起,没有响应,没有任何异常.
这是请求示例:
public async Task GetAsync(string uri){尝试{var response = await client.GetAsync(uri);}catch (RefreshTokenException ex){抛出新的 SessionExpiredException(AppResources.Error_SessionExpired);}}
如果我改用 JsonServiceClient - 在 RefreshToken 到期后,我会按预期收到 RefreshTokenException
也许有人对此有一些修复或解决方法.谢谢
我已经重写了 JsonHttpClient
手册任务延续以在 此提交 应该在 Xamarin 中使用经过更好测试的代码路径.
此更改可从最新的 ServiceStack v5.9.1 中获得,现在 MyGet 上提供.>
如果仍然存在问题,您可以尝试配置 JsonHttpClient
以使用 Xamarin 的原生 HttpClient 实现,适用于使用 NSUrlSessionHandler
的 iOS 和使用 AndroidClientHandler
的 Android.
I'm using ServiceStack JsonHttpClient client (5.9.0) in my Xamarin.Forms mobile app.
Client is set like this:
client = new JsonHttpClient(App.BaseEndpoint)
{
RefreshToken = RefreshToken,
};
var httpClient = client.GetHttpClient();
httpClient.Timeout = new TimeSpan(0, timeout, 0);
Refreshing of Bearer token works perfect, but after Refresh Token expires request just hangs with no response and without any exception.
here is request example:
public async Task GetAsync(string uri)
{
try
{
var response = await client.GetAsync<string>(uri);
}
catch (RefreshTokenException ex)
{
throw new SessionExpiredException(AppResources.Error_SessionExpired);
}
}
If I use JsonServiceClient instead - after expiration of RefreshToken I'm getting RefreshTokenException as expected
Maybe someone have some fix or workaround for this. Thanks
I've rewritten the JsonHttpClient
manual Task continuations to use async/await in this commit which should use a better tested code path in Xamarin.
This change is available from the latest ServiceStack v5.9.1 that's now available on MyGet.
If it's still an issue you can try configuring JsonHttpClient
to use the Xamarin's native HttpClient implementations for iOS using NSUrlSessionHandler
and for Android using AndroidClientHandler
.
这篇关于RefreshToken 过期后请求挂起 JsonHttpClient ServiceStack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!