小编Jed*_*Jed的帖子

HttpClient 证书错误

有人可以告诉我为什么这会引发证书无效的错误吗?在 中PowerShell,当我使用 IP 地址Invoke-WebRequest并设置主机标头以匹配证书中的 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);
Run Code Online (Sandbox Code Playgroud)

错误:

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.
Run Code Online (Sandbox Code Playgroud)

此代码是监控实用程序的一部分,我们需要能够探测负载均衡器后面的每个 Web 前端。我们经常使用 PowerShell 执行此操作,只要我设置主机标头以匹配证书,我就从未见过此问题。

c# ssl certificate httpclient

4
推荐指数
1
解决办法
4597
查看次数

标签 统计

c# ×1

certificate ×1

httpclient ×1

ssl ×1