原始出處:www.cnblogs.com/Charltsing/p/Net4TLS12.html
作者QQ: 564955427
最近提交請求發生錯誤:不支持請求的協議,研究了一下TLS1.2,發現這玩意的支持和.Net環境的版本有關
//SecurityProtocolType.Tls1.0=0xC0; SecurityProtocolType.Tls1.1=0x300; SecurityProtocolType.Tls1.2=0xC00;
//.net 4.0/4.5默認值:SecurityProtocolType.Tls | SecurityProtocolType.Ssl3
//.net 4.6/4.7默認值:SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12
//https://support.microsoft.com/en-us/help/3069494/cannot-connect-to-a-server-by-using-the-servicepointmanager-or-sslstre
//SCH_USE_STRONG_CRYPTO 此標志將在.NET Framework 4.6中自動使用
//https://support.microsoft.com/en-us/help/3154518/support-for-tls-system-default-versions-included-in-the-net-framework 在Win7Sp1和.Net 3.5.1中,支持TLS1.2
ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3; //關閉ssl3
ServicePointManager.SecurityProtocol |= (SecurityProtocolType)0x300 | (SecurityProtocolType)0xc00; //增加1.1和1.2支持
//TLS1.2的結論是這樣的:
//1、安裝.Net3.5.1需要打個補丁,然后增加TLS1.2枚舉
//2、安裝.Net 4.0需要修改注冊表,然后增加TLS1.2枚舉
//3、安裝.Net4.5之后,還需要增加TLS1.2枚舉
//4、安裝.Net4.6.1之后,默認支持TLS1.2
.net4下的注冊表修改
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319]
"SchUseStrongCrypto"=dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319]
"SchUseStrongCrypto"=dword:00000001