【发布时间】:2018-04-04 19:36:18
【问题描述】:
我一直在尝试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。我已向 chrome 添加了简单的 REST 客户端扩展,并成功测试了 URL。它在GetResponse 上失败。
我错过了什么?
【问题讨论】:
-
您是否尝试过使用
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;?这会奏效。