1 回答
TA贡献1785条经验 获得超8个赞
似乎还没有修复,解决方法如下。
1.引用System.Net.Http.WinHttpHandler
Nuget包来访问.NET Core中的WinHttpHandler。
2.创建一个新的MyKeyVaultCredential,继承自KeyVaultCredential并重写ProcessHttpRequestAsync
方法
public override async Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request == null)
{
throw new ArgumentNullException("request");
}
var accessToken = await PreAuthenticate(request.RequestUri).ConfigureAwait(false);
if (!string.IsNullOrEmpty(accessToken))
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
else
{
var httpClientHandler = new WinHttpHandler()
{
WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseCustomProxy,
Proxy = new MyWebProxy(configuration),
SendTimeout = TimeSpan.FromSeconds(120),
ReceiveDataTimeout = TimeSpan.FromSeconds(120),
ReceiveHeadersTimeout = TimeSpan.FromSeconds(120),
};
3.当我实例化 KeyVaultService 时,我必须向 WinHttpHandler 提供我的代理和新的密钥保管库凭据实例。
var httpClientHandler = new WinHttpHandler()
{
WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseCustomProxy,
Proxy = new MyWebProxy(configuration),
SendTimeout = TimeSpan.FromSeconds(120),
ReceiveDataTimeout = TimeSpan.FromSeconds(120),
ReceiveHeadersTimeout= TimeSpan.FromSeconds(120),
};
var httpClient = new HttpClient(httpClientHandler);
client = new KeyVaultClient(new MyKeyVaultCredential(configuration, GetToken), httpClient)
希望这可以帮助。
- 1 回答
- 0 关注
- 66 浏览
添加回答
举报