错误“基础连接已关闭:远程服务器上的发送出现意外错误”

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

我有一个相当简单的代码,直到最近才工作,直到它发送数据的站点没有切换到https。在调试模式下(在本地主机上),我使用通过域登录和密码访问的代理。在发布模式下,我使用另一个不需要凭据的代理。我试着补充一下

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

它不起作用!而只是一半。如果凭证是以调试模式发送的,则发送请求,但是除了“基础连接已关闭:如果您使用DefaultCredentials”之外,请求将被取消。您可以给我什么建议?

#if DEBUG //OK
        NetworkCredential proxyCreds = new NetworkCredential(
            "login",
            "password"
        );

        WebProxy proxy = new WebProxy("http://bproxy.com:3131", false)
        {
            UseDefaultCredentials = false,
            Credentials = proxyCreds,
        };

        HttpClient client = null;
        HttpClientHandler httpClientHandler = new HttpClientHandler()
        {
            Proxy = proxy,
            PreAuthenticate = true,
            UseDefaultCredentials = false,
        };

        client = new HttpClient(httpClientHandler);
#else   // NOT OK
        HttpClientHandler httpClientHandler = new HttpClientHandler()
        {
            Proxy = new WebProxy(new Uri("http://bproxy.com:3128"))
        };

        HttpClient client = new HttpClient(httpClientHandler);
#endif

        client.BaseAddress = new Uri("http://url.com");
        ServicePointManager.SecurityProtocol = 
            SecurityProtocolType.Tls12 | 
            SecurityProtocolType.Tls11 | 
            SecurityProtocolType.Tls;

        var values = new Dictionary<string, string>
        {
           {"_method", "POST" },
           { "data[User][email]", user },
           { "data[User][password]", pass }
        };

        var content = new FormUrlEncodedContent(values);

        var responseString = Post(client, "/", content);
c# ssl
1个回答
0
投票

我认为您需要将您在托管它的网络上使用的代理地址列入白名单。将IP或代理地址列入白名单,包括端口

与您的网络团队沟通。

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