调用HTTPS服务的问题
Posted xuexiaodong2009
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了调用HTTPS服务的问题相关的知识,希望对你有一定的参考价值。
调用HTTPS的服务需要处理安全协议,如果不处理就会提示安全协议错误
C#的处理代码如下
private static string ChangehttpsTohttp(string URL)
if (string.IsNullOrEmpty(URL))
throw new Exception("hisURI错误,为=" + URL);
URL = URL.ToLower().TrimStart();
if (URL.StartsWith("https"))
ServicePointManager.ServerCertificateValidationCallback += ValidateServerCertificate;
try
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
catch (Exception e)
/* 部分电脑的错误
System.NotSupportedException: The requested security protocol is not supported.
*/
LogInfo.Error("https协议错误:hisURI" + URL, e);
return URL;
private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
if(sslPolicyErrors!=SslPolicyErrors.None)
LogInfo.Error("https协议错误:sslPolicyErrors=" + sslPolicyErrors);
return true;
以上是关于调用HTTPS服务的问题的主要内容,如果未能解决你的问题,请参考以下文章