gpt4 book ai didi

c# - 未找到 .net 核心中的 Web 请求处理程序?

转载 作者:行者123 更新时间:2023-12-03 20:25:40 25 4
gpt4 key购买 nike

基本上我从 .framework 迁移至 .core然后我遇到了一个错误,找不到 Web 请求处理程序。我搜索了 .netcore 的替代方法here .

是否有其他注册 Web 请求处理程序的方法?

error

Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'WebRequestHandler' could not be found
(are you missing a using directive or an assembly reference?)
public HttpClient ConfigureHttpClient(Configuration.Configuration config)
{
WebRequestHandler mtlsHandler = new WebRequestHandler
{
UseProxy = true,
UseCookies = false,
CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore),
AuthenticationLevel = AuthenticationLevel.MutualAuthRequired,
AllowAutoRedirect = false
};
}

最佳答案

在 .netcore 中,等效项是 HttpClientHandler , 描述 here .出于 post 中提到的一些原因您已经引用了,HttpClientHandler公开的选项少于 WebRequestHandler .

下面是配置 HttpClient 的代码以类似于您的示例的方式,使用 HttpClientHandler :

var mtlsHandler = new HttpClientHandler {
UseProxy = true,
UseCookies = false,
AllowAutoRedirect = false
// CachePolicy = ... not supported and set to HttpRequestLevel.BypassCache equivalent, see https://github.com/dotnet/runtime/issues/21799
// AuthenticationLevel = ... need to implement it yourself by deriving from HttpClientHandler, see https://stackoverflow.com/questions/43272530/whats-the-alternative-to-webrequesthandler-in-net-core
};

var httpClient = new HttpClient(mtlsHandler);

不幸的是,还有 2 个 Unresolved 方面,都需要在 HttpClientHandler 之上进行您自己的自定义实现:
  • 不支持 CachePolicy除了 BypassCache 等效项,讨论了 here .
  • 不支持 AuthenticationLevel , 讨论 here .
  • 关于c# - 未找到 .net 核心中的 Web 请求处理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61981331/

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