Error: Exception: The underlying connection was closed: Could not establish trus

267 阅读1分钟

Client连Server连不上

Exception: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel


ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

var client = new HttpClient();
client.BaseAddress = new Uri("https://myapi");

解决办法:把ServicePointManager.ServerCertificateValidationCallback写在httpClient前面

C# Ignore certificate errors

Exception: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel