.NET Core 3.1中的默认代理 [英] Default Proxy in .NET Core 3.1

查看:63
本文介绍了.NET Core 3.1中的默认代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关.NET Core 3.1的帮助,以获取需要脱离公司代理的代码.通过将以下内容放入app.config中,代码可在.NET 4.7.2中工作.据我在本网站上了解到的(谢谢!),它允许一个人通过企业代理服务器.

I need some help with .NET Core 3.1 for code that needs to get out of the corporate proxy. The code works in .NET 4.7.2 by putting the following in the app.config. This, I learned on this site (Thank you!), allows one to get through the corporate proxy server.

 <system.net>
    <defaultProxy useDefaultCredentials="true">
    </defaultProxy>
  </system.net>

以下代码段在.NET 4.7.2中有效,并且可以通过代理.代理存储为名为ALL_PROXY的env变量,其值为http://我们的内部proxy:port(请参阅[

The following code snippet works in .NET 4.7.2, and can get out past the proxy. The proxy is stored as an env variable named ALL_PROXY with a value of http:// our internal proxy:port (see [https://github.com/dotnet/corefx/pull/37238/commits/9ba8879ea104afac9dea9a78d3009b5bc700b7c3][1]). This is an Azure Cognitive service, so you will need a key vault, and a Cognitive Service.

  var keyVaultName = Environment.GetEnvironmentVariable("KEY_VAULT_NAME");
  var kvUri = string.Format("{0}{1}{2}", 
                "https://", 
                keyVaultName, 
                ".vault.azure.net");
  var secretClient = new SecretClient(new Uri(kvUri), 
                new DefaultAzureCredential());
  KeyVaultSecret secret = secretClient.GetSecret("FacesSubscription");
  var subscriptionKey = secret.Value;

  var credentials = new ApiKeyServiceClientCredentials(subscriptionKey);
  var textClient = new TextAnalyticsClient(credentials)
  {
      Endpoint = endpoint
   };

在.Net核心上,我收到http 407异常. Azure.RequestFailedException:'服务请求失败.状态:407(ADAuth-AuthenticationFailed)此异常发生在KeyVaultSecret行上.

On .Net core, I get an http 407 exception. Azure.RequestFailedException: 'Service request failed. Status: 407 (ADAuth-AuthenticationFailed) This exception occurs on the KeyVaultSecret line.

我已经研究了这个问题@

I have researched the issue @

https://github.com/dotnet/corefx/pull/37238

https://github.com/dotnet/corefx/pull/37333

https://github.com/dotnet/runtime/issues/29147

并尝试添加代码,例如

var handler = new HttpClientHandler();
handler.DefaultProxyCredentials = CredentialCache.DefaultCredentials;
var httpClient = new HttpClient(handler);

我通过了单元测试来检查签入,但是它们似乎都与Web代理有关.上面的链接提供了有关如何实现代理的详细信息.

I looked through the unit tests for the check-ins, but they all seemed to be about web proxies. The links above provide details of how the proxy is implemented.

有人对使用Azure服务通过NET Core中的工作代理有想法吗?

Does anyone have idea around getting through a work proxy in NET Core with Azure services?

谢谢.

推荐答案

我遇到了类似的问题,并且此问题已得到解决:

I have had a similar issue and this fixed it:

IWebProxy proxy = WebRequest.GetSystemWebProxy();
proxy.Credentials = CredentialCache.DefaultCredentials;
HttpClient.DefaultProxy = proxy;

这篇关于.NET Core 3.1中的默认代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆