問題:
- 使用HttpWebRequest webRequest方法,遠端傳回
Could not establish trust relationship for the SSL/TLS secure channel
原因是因為網頁會詢問你是否繼續。
所以再詢問前加上
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; - 另外,有可能因為TLS版本不同導致呼叫失敗。可以加上ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
範例:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
HttpWebRequest webRequest=(HttpWebRequest)WebRequest.Create("https://api.com");