首页 > Web开发 > 详细

HttpClient DelegatingHandler管道扩展Bug小计

时间:2021-03-17 17:26:59      阅读:47      评论:0      收藏:0      [点我收藏+]

在项目中自定义了一个HttpClientLoggingHandler用来记录httpclient发送请求的输入输出日志。运行后调用了几次抛出异常

The ‘InnerHandler‘ property must be null. ‘DelegatingHandler‘ instances provided to ‘HttpMessageHandlerBuilder‘ must not be reused or cached. 
Handler: ‘EM.Passport.Badge.Service.Infrastructure.WebApi.HttpClientLoggingHandler‘	

检查代码发现自己在注入HttpClientLoggingHandler时,生命周期选择的是AddSingleton。而异常错误很明显说明管道中的DelegatingHandler不能复用或缓存。所以将注入的生命周期修改为AddScoped

问题解决!

HttpClient DelegatingHandler管道扩展Bug小计

原文:https://www.cnblogs.com/gt1987/p/14548279.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!