c# - 从 Flurl 重放 HttpCall
问题描述
我正在编写一个错误处理程序来处理令牌刷新。当我收到expired_token
错误时,我正在刷新令牌,我想重播请求,但我不确定如何
public async Task HandleErrorAsync(HttpCall call)
{
var exception = call.Exception;
if (exception is FlurlHttpException)
{
FlurlHttpException ex = (exception as FlurlHttpException);
var errorResponse = await ex.GetResponseJsonAsync<ErrorResponse>();
if(errorResponse.Errors.Any(x => x.Id == EXPIRED_TOKEN))
{
await this.RefreshOAuthToken();
//How can I Replay the request
//call.Response = call.Request.Replay();
call.ExceptionHandled = true;
}
}
}
刷新令牌后,我可以访问刚刚抛出过期令牌错误的 HttpCall 对象。我想重播请求并替换响应,但我不知道该怎么做。
如何在 Flurl 中重放来自 HttpCall 的请求?
解决方案
我发现一个重载一般发送我的请求,我做了一个扩展方法
public static async Task<HttpCall> Replay(this HttpCall call)
{
call.Response = await call.FlurlRequest.SendAsync(call.Request.Method, call.Request.Content);
return call;
}
推荐阅读
- playframework - JSON 的 Play Framework 分块响应处理
- c - 2 函数对齐的强制力量 st 对齐 % 其他值 == 对齐
- c++ - C++ 模板继承
- slack - 在完整消息中扩展 slack bot 菜单颜色条(节点、slack 块套件、slack api)
- c - 如何检查 ioctl 是否执行?
- php - Symfony 5 中 EntityType 的数据覆盖问题(与 ChoiceType 相同的问题)
- python - 我将如何计算在 PIL 中保持两个绘制句子之间的空间所需的 X 坐标?
- python - 我可以用另一个在 python 中具有相同键的字典的值来更改字典的键吗?
- swift - 快速获取每天的睡眠总数
- asp.net-core-mvc - 如何在 ASP.Net Core 的 HTML 标记中添加 c# 代码