如何正确指定System.Net.HttpClient的代理

问题描述 投票:1回答:1

如果在web.config中指定了,任何人都可以回答HttpClient是否应该使用默认代理吗?

<system.net>
    <defaultProxy enabled="true" useDefaultCredentials="true">
        <proxy proxyaddress="http://my.proxy" bypassonlocal="False" />
    </defaultProxy>
</system.net>

[每当我使用HttpClient时,我都会发现自己必须实现静态HttpClientHandler

private static HttpClientHandler statichandler = new HttpClientHandler()
{
    Proxy = new WebProxy(ConfigurationManager.AppSettings["HttpClientProxy"].ToString()),
            UseProxy = true,
};

有没有一种方法可以强制httpclient提取system.net默认配置部分/我缺少什么?

asp.net web-config dotnet-httpclient .net-4.7.1
1个回答
0
投票

实际的解决方案是使用HttpClientHandler实现Httpclient,将UseProxy显式设置为true。

© www.soinside.com 2019 - 2024. All rights reserved.