使用脚本任务连接到 RESTful 站点

Connecting to RESTful site using Script Task

我一直在尝试 HttpWebRequest 对象(在 SSIS 中)的各种组合来连接到 Web 服务地理编码站点以拉回个人地理编码信息,但没有成功。这是一个 JSON 响应和 https URL。

        string wUrl = "https://geocoding.geo.census.gov/geocoder/geographies/onelineaddress?address=1600+Pennsylvania+Ave+NW,+Washington,+DC,+20500&benchmark=Public_AR_Current&vintage=4&format=json";
        X509Certificate cert = X509Certificate.CreateFromCertFile("C:\Users\kwhauser\geocode.cer");

        HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(wUrl);
        //WebRequest httpWReq = WebRequest.Create(wUrl);
        //httpWReq.Method = "GET";
        httpWReq.ClientCertificates.Add(cert);
        //httpWReq.ContentType = "application/json";

        //ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, ssl) => true;
        //ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

        //HttpWebResponse httpWResp = (HttpWebResponse)httpWReq.GetResponse();
        //HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
        try
        {
            HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
            //WebResponse response = httpWReq.GetResponse();
            //Stream responseStream = response.GetResponseStream();

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
            if (ex.InnerException != null)
                MessageBox.Show(" InnerException: " + ex.InnerException.Message);

        }

不管我尝试从文件加载证书还是使用回调证书,我仍然收到相同的错误消息:

System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.

DotNet 框架版本为 4.7。该站点需要 TLS12。我已将简单的 REST 客户端扩展添加到 chrome 并成功测试了 URL。它在 GetResponse.

上失败

我错过了什么?

System.Net.ServicePointManager.SecurityProtocol = (System.Net.SecurityProtocolType)3072;