【发布时间】:2017-11-30 17:42:04
【问题描述】:
谁能告诉我为什么这会引发证书无效的错误?在PowerShell 中,当我使用Invoke-WebRequest 中的IP 地址并将主机头设置为与证书中的CN 匹配时,我没有收到证书错误。我会假设HttpClient 会是一样的吗?
var spHandler = new HttpClientHandler();
var spClient = new HttpClient(spHandler);
spClient.BaseAddress = new Uri("https://10.0.0.24");
var spRequest = new HttpRequestMessage(HttpMethod.Get, "/api/controller/");
spRequest.Headers.Host = "somehost.com";
var spResponse = await spClient.SendAsync(spRequest);
错误:
WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
AuthenticationException: The remote certificate is invalid according to the validation procedure.
此代码是监控实用程序的一部分,我们需要能够探测负载平衡器后面的每个 Web 前端。我们经常使用 PowerShell 执行此操作,只要我将 Host 标头设置为与证书匹配,我就从未见过此问题。
【问题讨论】:
标签: c# ssl certificate httpclient