【发布时间】:2018-04-24 16:56:04
【问题描述】:
我的问题特别是在 .net 标准 2.0 中,因为我不完全确定的原因似乎相同的代码在 .net 框架上工作。
问题是我想向使用自签名证书的服务器发出 http 请求。现在在 .net 框架(特别是 4.6.1)中解决这个问题的方法是使用:
ServicePointManager.ServerCertificateValidationCallback = CustomValidation;
public static bool CustomValidation
(object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors policyErrors)
{
return true;
}
这解决了问题。但是,在 .net 标准中执行此操作似乎可以编译但同样的错误(WinHttpException - 发生安全错误) System.AggregateException 发生 H结果=0x80131500 Message=发生了一个或多个错误。 (发送请求时出错。) 来源= 堆栈跟踪: 在 System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) 在 C:\Users\Nick\source\repos\matrix-tester\Program.cs:line 11 中的 matrix_tester.Program.Main(String[] args) 处
内部异常 1: HttpRequestException: 发送请求时出错。
内部异常 2: WinHttpException: 发生安全错误
我的智慧到此为止。 .net 标准中不使用 ServicePointManager 吗?
【问题讨论】:
-
您是否找到任何解决方案来绕过使用 .NET 标准 2.0 的自签名证书?