第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

“請(qǐng)求被中止:無法創(chuàng)建 SSL/TLS 安全通道”第一次訪問 API 時(shí)

“請(qǐng)求被中止:無法創(chuàng)建 SSL/TLS 安全通道”第一次訪問 API 時(shí)

C#
森欄 2022-12-24 09:33:51
我正在嘗試從 Web API 使用客戶端的 Web 服務(wù),下面是我們目前用來繞過 SSL 證書的代碼ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;它工作正常,直到他們最終禁用了 TLS 1.0 和 TLS 1.1。現(xiàn)在我們添加了以下代碼以使用 TLS 1.2 進(jìn)行客戶端服務(wù)器連接ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;現(xiàn)在我收到“請(qǐng)求已中止:無法創(chuàng)建 SSL/TLS 安全通道?!?nbsp;僅當(dāng)我第一次訪問 API 時(shí)出錯(cuò),然后如果我連續(xù)訪問 API 會(huì)得到結(jié)果,如果我等待大約一分鐘左右的時(shí)間,再次僅在第一次訪問時(shí)出現(xiàn)相同的錯(cuò)誤。
查看完整描述

3 回答

?
精慕HU

TA貢獻(xiàn)1845條經(jīng)驗(yàn) 獲得超8個(gè)贊

設(shè)置安全協(xié)議類型需要在創(chuàng)建發(fā)布請(qǐng)求之前完成。所以這:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

應(yīng)該出現(xiàn)在這之前:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

因此,如果您看到它對(duì)后續(xù)請(qǐng)求有效,則可能是您設(shè)置協(xié)議的時(shí)間太晚了。


查看完整回答
反對(duì) 回復(fù) 2022-12-24
?
慕蓋茨4494581

TA貢獻(xiàn)1850條經(jīng)驗(yàn) 獲得超11個(gè)贊

以下代碼可用于幫助解決問題。


ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

ServicePointManager.ServerCertificateValidationCallback += ValidateServerCertificate;


...


private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

{

    // If the certificate is a valid, signed certificate, return true to short circuit any add'l processing.

    if (sslPolicyErrors == SslPolicyErrors.None)

    {

        return true;

    }

    else

    {

        // cast cert as v2 in order to expose thumbprint prop - if needed

        var requestCertificate = (X509Certificate2)certificate;


        // init string builder for creating a long log entry

        var logEntry = new StringBuilder();


        // capture initial info for the log entry

        logEntry.AppendFormat("SSL Policy Error(s): {0} - Cert Issuer: {1} - SubjectName: {2}",

           sslPolicyErrors.ToString(),

           requestCertificate.Issuer,

           requestCertificate.SubjectName.Name);


        // check for other error types as needed

        if (sslPolicyErrors == SslPolicyErrors.RemoteCertificateChainErrors) //Root CA problem

        {

            // check chain status and log

            if (chain != null && chain.ChainStatus != null)

            {

                // check errors in chain and add to log entry

                foreach (var chainStatus in chain.ChainStatus)

                {

                    logEntry.AppendFormat("|Chain Status: {0} - {1}", chainStatus.Status.ToString(), chainStatus.StatusInformation.Trim());

                }

            }

        }


        // replace with your logger

        MyLogger.Info(logEntry.ToString().Trim());

    }


    return false;

}


查看完整回答
反對(duì) 回復(fù) 2022-12-24
?
慕尼黑5688855

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超2個(gè)贊

對(duì)于運(yùn)行 .NET 版本 4 的用戶,他們可以使用下面的


ServicePointManager.SecurityProtocol = CType(768, SecurityProtocolType) Or CType(3072,SecurityProtocolType)

ServicePointManager.Expect100Continue = True


查看完整回答
反對(duì) 回復(fù) 2022-12-24
  • 3 回答
  • 0 關(guān)注
  • 420 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)