簡體   English   中英

未找到 .net 核心中的 Web 請求處理程序?

[英]Web request handler in .net core not found?

基本上我從.framework遷移到.core然后我遇到了一個錯誤,Web request handler is not found。 在這里搜索了.netcore的替代方法。

還有其他注冊 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在此處進行了描述。 由於您已經引用過的帖子中提到的一些原因, HttpClientHandler公開的選項比WebRequestHandler少。

下面是使用HttpClientHandler以類似於您的示例的方式配置HttpClient的代碼:

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);

不幸的是,還有兩個未解決的方面,都需要在 HttpClientHandler 之上進行自己的自定義實現:

  1. 除了 BypassCache 等效項之外,不支持CachePolicy ,在此處討論。
  2. 不支持AuthenticationLevel這里討論。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM