Toolbelt.blazor.httpclientinterceptor: 查看来自服务器的消息

创建于 2020-01-22  ·  7评论  ·  资料来源: jsakamoto/Toolbelt.Blazor.HttpClientInterceptor

是否可以看到来自服务器的响应消息,如果可以,您可以发布一个示例吗?

我正在尝试使用它来现场放置“错误”吐司,因此我需要能够看到请求何时返回错误。

谢谢!

所有7条评论

一种解决方案是将 SendAsync 方法更改为:

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            HttpResponseMessage response = null;
            try
            {
                BeforeSend?.Invoke(this, request);
                response = await (SendAsyncMethod.Invoke(Handler, new object[] { request, cancellationToken }) as Task<HttpResponseMessage>);
                return response;
            }
            finally
            {
                AfterSend?.Invoke(this, response);
            }
        }

和事件处理程序

/// <summary>
/// Occurs before a HTTP request sending.
/// </summary>
public event EventHandler<HttpRequestMessage> BeforeSend;

/// <summary>
/// Occurs after received a response of a HTTP request. (include it wasn't succeeded.)
/// </summary>
public event EventHandler<HttpResponseMessage> AfterSend;

我接受了这个建议。 Sorta 似乎首先应该是这样。 使这个拦截器更加有用,除非我不理解EventArgs e的用处

感谢您的反馈! 👍

我发布了“Blazor WebAssembly(客户端)HttpClient Interceptor”v.6.1.0,其中包含@khamang建议的新功能!

另请参阅: https ://github.com/jsakamoto/Toolbelt.Blazor.HttpClientInterceptor/#the -arguments-of-event-handler

所以这应该修复吗? 如果我想访问 AfterSend 中的响应内容,我仍然会收到错误消息。
它在服务中说使 http.PostAsync 无法访问正文,因为它已被锁定

@TheSwerik感谢您的报告。

所以这应该修复吗? 我仍然收到错误...

此线程不是错误报告,这是一个新功能提案线程。
我从来不知道它有你现在报告的问题。

稍后我将尝试重现该问题,如果可以重现它,我将尝试修复它。

哦,我认为这适合这里,我将创建一个新的更详细的问题

@TheSwerik谢谢!

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

WebFreak001 picture WebFreak001  ·  3评论

DamianEdwards picture DamianEdwards  ·  3评论

QuantumDeveloper picture QuantumDeveloper  ·  3评论

radleta picture radleta  ·  3评论

DmitryEfimenko picture DmitryEfimenko  ·  3评论