我正在尝试使用具有自签名证书的本地 Web 服务器上的 REST API。在运行时,应用程序抛出错误
AuthenticationException:根据验证过程,远程证书无效。
我已尝试在此答案中进行修复: https: //stackoverflow.com/a/1386568/8980983,但错误仍然存在。代码如下:
static void Main(string[] args)
{
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Clear();
ServicePointManager.ServerCertificateValidationCallback = delegate (
object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};
var loginPage = httpClient.GetAsync("https://<local IP address>/loginpage.html").GetAwaiter().GetResult();
//do stuff with response...
}
Run Code Online (Sandbox Code Playgroud)
我可以采取哪些措施来有效忽略 SSL 策略错误?