想使用https访问asp.net core的API,从腾讯云上申请了免费的自签名证书,但是因为绑定的域名,用域名访问又需要备案麻烦,所以想客户端测试暂时用IP地址进行,但是在访问的时候报错。
The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch
因为证书是绑定域名的,用IP地址访问会报证书校验失败,可以通过如下代码跳过客户端证书检查。
HttpClientHandler clientHandler = new HttpClientHandler(); clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, SslPolicyErrors) => { return true; }; HttpClient client = new HttpClient(clientHandler);
标签:证书,域名,clientHandler,访问,HttpClientHandler,https From: https://www.cnblogs.com/Farseer1215/p/17608182.html