调用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服务的问题的主要内容,如果未能解决你的问题,请参考以下文章

如何测量代码片段的调用次数和经过时间

如何从片段中调用 getSupportFragmentManager()?

调用模板化成员函数:帮助我理解另一个 *** 帖子中的代码片段

在片段的后按防止使用导航图调用前一个片段的 onViewCreated

Android片段生命周期:onResume调用了两次

在不存在的片段上调用片段生命周期和 onCreate 的问题