asp.net核心defaultProxy [英] asp.net core defaultProxy

查看:104
本文介绍了asp.net核心defaultProxy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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核心或测试中我们找不到像上面这样的解决方案 有人可以帮我吗?

but in asp.net core or test we can't found a solution like the above Could someone please help me?

非常感谢您的帮助

谢谢!

推荐答案

虽然可以在可能使用HttpClientHander的情况下手动设置代理,但默认情况下,所有请求都无需编写代码即可,就像您在.NET中所做的那样.目前尚无法使用框架.如果您使用的库没有公开此功能,那真是太可惜了.

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永远一样)就可以实现:

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/36553HttpClient上添加了一个新的静态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核心defaultProxy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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