--- tags: Web, C# authors: Anderson --- ###### tags: `Web` `C#` # error : System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel. ## :memo: 問題 error : System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel. ## :memo: 原因 因對象網站使用的安全協定關閉較舊的版本SSL3.0/TLS1.0/TLS1.1 來源:[SSL3.0/TLS1.0/TLS1.1壽終正寢 主流瀏覽器擁抱TLS1.2/TLS1.3](https://kknews.cc/tech/9zoyvzl.html) ## :memo: 解決 設定使用的安全協定 **ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;** 參考: 1. [The request was aborted: Could not create SSL/TLS secure channel](https://stackoverflow.com/questions/2859790/the-request-was-aborted-could-not-create-ssl-tls-secure-channel) 2. [C# 連線 HTTPS 網站發生驗證失敗導致基礎連接已關閉](https://blog.darkthread.net/blog/webclient-and-tls12/) ```csharp= Private void DownloadData() { ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var jsonStr = new WebClient().DownloadString("http://portal.sw.nat.gov.tw/APGQ/GC331!downLoad?formBean.downLoadFile=CURRENT_JSON"); JObject jsonObject = JsonConvert.DeserializeObject<JObject>(jsonStr); var startDate = this.ParseToDateString(jsonObject["start"].ToString()); var endDate = this.ParseToDateString(jsonObject["end"].ToString()); var items = jsonObject["items"].ToString(); } ``` ## :memo: 補充 [快速檢測網站是否已關閉 TLS 1.1/1.0](https://blog.darkthread.net/blog/check-tls-version/) [檢測網站](https://www.ssllabs.com/ssltest/")
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up