【发布时间】:2020-11-30 13:33:06
【问题描述】:
我发现向启用 SSL 的 API 发送 http 请求时出现问题。 我得到的错误信息是 -
AuthenticationException: The remote certificate is invalid according to the validation procedure.
基于此请求
using (HttpResponseMessage res = client.GetAsync("https://example.com").Result)
{
using (HttpContent content = res.Content)
{
string data = content.ReadAsStringAsync().Result;
if (data != null)
{
Console.WriteLine(data);
}
else
{
Console.WriteLine("Nothing returned");
}
}
}
我得到了一个 .pem 文件来验证发回的证书是否由我们的 CA 签名,并且在弄清楚如何在 C# 中执行此操作时遇到了一些麻烦
在 python 中,我可以通过将 .pem 文件传递给验证参数来解决证书错误,例如
r = requests.post(url="https://example.com", headers=headers, verify='mypem.pem')
Dotnet Core 3 的 HttpClient 中是否有类似的东西?
感谢您的帮助!
【问题讨论】: