0

我的应用程序遇到了问题。尝试使用 ZipWise.com 的 api 获取一些邮政编码时,我收到错误“请求被中止:无法创建 SSL/TLS 安全通道。” 我没有对程序进行任何更改,它突然停止允许我使用他们的 API。在创建请求之前,我尝试将其添加到代码的开头:

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

我在服务器上禁用了 TLS 1.0、TLS 1.1、SSL 2.0 和 SSL 3.0(并重新启动)。我可以毫无问题地在浏览器中打开网址。我在 SSL Labs 上验证他们使用的是 TLS 1.2。

当我在我的开发 PC 上运行它时,它可以毫无问题地执行并返回一堆邮政编码。当我尝试在服务器上运行它时,它失败并给了我那个错误。

这是我在 Windows 窗体应用程序中使用的一些示例代码,它会产生相同的错误:

        private void button1_Click(object sender, EventArgs e)
    {
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        ServicePointManager.Expect100Continue = true;

        string url = "https://zipwise.com/webservices/radius.php?key=**********&zip=90210&radius=50";

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url));
        request.Method = "POST";

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();//exception occurs here

        StreamReader input = null;
        XDocument doc = null;

        if (response.StatusCode.Equals(HttpStatusCode.OK))
        {
            input = new StreamReader(response.GetResponseStream());
            doc = XDocument.Parse(input.ReadToEnd());
        }

        response.Close();
        request.ServicePoint.CloseConnectionGroup(request.ConnectionGroupName);

        if (input != null)
        {
            input.Close();

            var tempZips = (from z in doc.Descendants("result") select z.Descendants("zip").Single().Value).ToList();
            finalZips.AddRange(tempZips);

            foreach(string s in finalZips)
            {
                listBox1.Items.Add(s);
            }
        }
    }

任何帮助表示赞赏!

编辑:应用程序在 .NET 4.6 上运行,服务器上的 SSL 证书仍然有效。

4

0 回答 0