HTTPS連線,不管是在寫sql clr或者powershell,每次遇到以下二類SSL錯誤,都忘了要改啥。這次記錄下,以後可以參考。
System.Net.WebException: 基礎連接已關閉: 接收時發生未預期的錯誤。 ---> System.ComponentModel.Win32Exception: 用戶端和伺服器無法溝通,因為它們沒有公用的演算法
加入以下
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12| SecurityProtocolType.Tls13;
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: 基礎連接已關閉: 無法為 SSL/TLS 安全通道建立信任關係。 ---> System.Security.Authentication.AuthenticationException: 根據驗證程序,遠端憑證是無效的。
加入以下:
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
順便再加一段sql clr assembly,單純的呼叫GET方法 WEB URL,回傳respone內容。
沒有留言:
張貼留言