.NET Core 3.1中的默认代理

编程入门 行业动态 更新时间:2024-10-18 08:22:46
本文介绍了.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> <defaultProxy useDefaultCredentials="true"> </defaultProxy> </system>

以下代码段在.NET 4.7.2中有效,并且可以通过代理.代理存储为名为ALL_PROXY的env变量,其值为我们的内部proxy:port(请参阅[ github/dotnet/corefx/pull/37238/commits/9ba8879ea104afac9dea9a78d3009b5bc700b7c3] [1] ).这是一项Azure认知服务,因此您将需要一个密钥保险库和一个认知服务.

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 our internal proxy:port (see [github/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}", "", keyVaultName, ".vault.azure"); 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 @

  • [ github/dotnet/corefx/pull/37238/commits/9ba8879ea104afac9dea9a78d3009b5bc700b7c3] [1]

github/dotnet/corefx/pull/37238

github/dotnet/corefx/pull/37333

github/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中的默认代理

本文发布于:2023-11-14 19:53:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1588367.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NET   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!