我有问题。每当我将WebRequest发送到https://myaddress.com时,它都会解析为错误的IP地址(此域有多个IP地址)。如何指定我想将WebRequest发送到的IP地址?
var uri = new Uri(url);
var changedUrl = "{0}://{1}:{2}{3}".FormatWith(uri.Scheme, ipWithPort.Ip, ipWithPort.Port, uri.PathAndQuery);
webRequest = (HttpWebRequest)WebRequest.Create(changedUrl);
webRequest.Host = uri.Authority;
如果uri计划 - http 工作正常,但 https 提升证书验证失败:
ServicePointManager.ServerCertificateValidationCallback +=
new System.Net.Security.RemoteCertificateValidationCallback((s, ce, ch, ssl) =>
{
return ssl == System.Net.Security.SslPolicyErrors.None;
});
在这种情况下,ssl是SslPolicyErrors.RemoteCertificateChainErrors。 注意:始终返回true不是解决方案。
动态编辑主机文件?也许是它的解决方案?