gpt4 book ai didi

asp.net - 在 Net Framework 上编写的应用程序中使用 WinHttpHandler 与 HttpClientHandler

转载 作者:行者123 更新时间:2023-12-02 12:00:51 25 4
gpt4 key购买 nike

对于 Net Framework 4.6.1+ 编写的应用程序,我们可以在 HttpClient 中使用至少 2 个处理程序,即:

  • HttpClientHandler(网络框架的一部分)
  • WinHttpHandler (提供通过 Nuget)

没有文章通过以下问题对它们进行比较:

  • 性能比较
  • 使用 DNS 转换(当 DNS FQDN 的 IP已更改)
  • 连接租用超时(当 HttpClient 不这样做时)自动缩放时自动移动到新实例)

有人可以分享一下您使用WinHttpHandler的经验吗?

最佳答案

Karel Zikmund在我的问题上写了答案,你可以通过下一个url看到它

Starting with .NET Core 2.1, the HttpClientHandler uses by default SocketsHttpHandler - new C# implementation over sockets.

It's key value is consistency across platforms and focus on performance (especially against CurlHandler on Linux/Mac).

WinHttpHandler is wrapper over winhttp OS component. If you need HTTP/2, it is currently the only option as SocketsHttpHandler does not support HTTP/2 yet (see #23134).

DNS changes behave the same behavior on both, however, you can tweak it somewhat via SocketsHttpHandler.PooledConnectionLifetime.

DNS TTL is not supported - see #24257 and #11224. The workaround is to recycle the handler on regular basis. You can also use higher-level wrapper HttpClientFactory which does that for you (at least as a motivation).

关于asp.net - 在 Net Framework 上编写的应用程序中使用 WinHttpHandler 与 HttpClientHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50365444/

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