請(qǐng)求被中止: 未能創(chuàng)建 SSL/TLS 安全通道

英文搜索關(guān)鍵詞 : the request was aborted could not create ssl/tls (net 4.6)

statckoverflow 上面大多答案如下:

ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

也有用如下的(強(qiáng)烈不建議使用)

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

原因:

  1. Tls1.0 由于安全原因,大部分https服務(wù)端已經(jīng)不再建議支持。

  2. .Net 4.5及之前的版本,不支持Tls1.2 ,SecurityProtocolType這個(gè)枚舉中沒有Tls12這個(gè)項(xiàng)

  3. Windows Server 2012 R2中,安裝了.Net 4.6.x或4.7.x后,雖然系統(tǒng)支持,.Net也支持,但是默認(rèn)的協(xié)商協(xié)議列表不包含Tls1.2

解決方案(PowerShell腳本):

查看當(dāng)前系統(tǒng)中默認(rèn)啟用的協(xié)商協(xié)議列表

[Net.ServicePointManager]::SecurityProtocol

打印出來的結(jié)果應(yīng)該是不包含Tls12 的,我實(shí)測的Win10 1603以及Windows Server 2012 R2顯示均為如下:

Ssl3, Tls

繼續(xù)執(zhí)行如下代碼,修改設(shè)置:

針對(duì)64位.Net:

Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord

針對(duì)32位.Net:

Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord

關(guān)閉PowerShell窗口,打開一個(gè)新的PowerShell窗口,執(zhí)行以下代碼

[Net.ServicePointManager]::SecurityProtocol

結(jié)果如下:

Tls, Tls11, Tls12, Tls13

重啟之前受影響的.Net應(yīng)用程序即可生效

.Net <4.5.x 參考鏈接 https://stackoverflow.com/questions/27953681/changing-security-protocol-per-request-httpclient

.Net 4.6.x參考鏈接 https://trailheadtechnology.com/solving-could-not-create-ssl-tls-secure-channel-error-in-net-4-6-x/

官方資料:https://docs.microsoft.com/en-us/security/solving-tls1-problem


ps: 然后以上處理并沒有解決我的問題。。。o(╥﹏╥)o

在生產(chǎn)機(jī)器上多次curl測試,發(fā)現(xiàn)偶爾才會(huì)出現(xiàn),并非必現(xiàn)。于是我很機(jī)智的,在出現(xiàn)此異常時(shí)重試三次。最終搞定了!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容