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

时间:2019-02-19 07:04:38

标签: c# ssl

我有一个相当简单的代码,直到最近才起作用,直到将数据发送到的站点未切换到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);

1 个答案:

答案 0 :(得分:0)

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

与您的网络团队沟通。