最近作了一個安裝包,安裝包會彈出dotnet的 窗體,這個安裝包會去調用https的一個api。用測試程序測試窗體都是好的。一旦打入安裝包後,就報錯。研究了半天,原來是https惹的禍api
:解決方案
.NET 4.6 and above. You don’t need to do any additional work to support TLS 1.2, it’s supported by default.DOTNET 4.6.1 以上版本,默認就能夠了app
.NET 4.5. TLS 1.2 is supported, but it’s not a default protocol. You need to opt-in to use it. The following code will make TLS 1.2 default, make sure to execute it before making a connection to secured resource:測試
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
this
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
spa
各類tls版本兼容寫法:code
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tlsit
其實默認配置DOTNET 4.6.1 以上版本就能夠了,可是由於我是安裝包,無法寫配置文件.....io
<startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> </startup>