我正在重写 WinForms 中的一些 Web 处理代码,并从 HttpWebRequest 切换到 HttpClient。我要求的最后一件事是我似乎无法找到如何完成。
在 HttpWebRequest 中,我可以从要连接的 Web 服务器捕获证书并显示它:
...
HttpWebRequest request = CreateHttpRequest(destUri);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
cert = request.ServicePoint.Certificate;
if (cert != null)
{
cert2 = new X509Certificate2(cert);
X509Certificate2UI.DisplayCertificate(cert2);
}
...
我找不到使用 HttpClient 捕获证书的等效方法:
//... Use HttpClient.
using (HttpClient client = new HttpClient())
{
using (HttpResponseMessage response = await client.GetAsync(destUri))
{
using (HttpContent content = response.Content)
{
string result = await content.ReadAsStringAsync();
}
}
}
我在这里如何/在哪里可以做到这一点?我不知道如何到达 ServicePoint.Certificate。