问题描述
在 net 4.5 中,我们正在使用这样的代理:
In net 4.5 we are working with proxy like this:
<system.net>
<!-- -->
<defaultProxy enabled="true" useDefaultCredentials="false">
<proxy usesystemdefault="True" proxyaddress="http://192.168.1.1:8888" bypassonlocal="True" autoDetect="False" />
<module type="CommonLibrary.Proxy.MyProxy, CommonLibrary, Version=1.0.0.0, Culture=neutral" />
</defaultProxy>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
<servicePointManager expect100Continue="false" />
</settings>
</system.net>
但是在 asp.net core 或 test 中我们找不到像上面这样的解决方案有人可以帮我吗?
but in asp.net core or test we can't found a solution like the above Could someone please help me?
非常感谢您的帮助
谢谢,问候
推荐答案
虽然在可以使用 HttpClientHander 时手动设置代理工作,但默认所有请求都不需要代码,就像你可以在 .NET Framework 中做目前是不可能的.如果您使用的是不公开此功能的库,那就太可惜了.
Whilst manually setting the proxy works when it's possible to use a HttpClientHander, defaulting all requests to do so without code, like you could do in the .NET Framework is currently not possible. Which is bummer if you're using a library that doesn't expose this functionality.
谢天谢地,从 .NET Core 3.0 开始,只需设置环境变量就可以实现这一点(即,其行为与 Linux 一直有效):https://github.com/dotnet/corefx/issues/37187
Thankfully, from .NET Core 3.0, this will be possible simply by setting environment variables (i.e. behaves exactly as Linux has worked forever): https://github.com/dotnet/corefx/issues/37187
或者,https://github.com/dotnet/corefx/issues/36553 在 HttpClient 上添加了一个新的静态 DefaultWebProxy 属性,这将允许您通过代码完成相同的事情.这也将在 Core 3.0 中提供.
Alternatively, https://github.com/dotnet/corefx/issues/36553 added a new static DefaultWebProxy property on HttpClient that will allow you to accomplish the same thing via code. This will also be available in Core 3.0.
这篇关于asp.net core defaultProxy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)