我的问题在.net标准2.0中具体提到,因为相同的代码似乎适用于.net框架,原因我并不完全确定。.net标准2.0中的自签名证书
问题是我想向使用自签名证书的服务器发出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 HResult = 0x80131500 消息=发生了一个或多个错误。 (发送请求时发生错误。) Source = StackTrace: at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at matrix_tester.Program.Main(String [] args)in C:\内部异常1: HttpRequestException:发送请求时发生错误。
内部异常2: WinHttpException:安全出错
我在我的智慧在这里结束。 ServicePointManager是否不能用于.net标准?
您是否发现了任何使用.NET标准2.0绕过自签名证书的解决方案? –