[英]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 之上進行自己的自定義實現:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.