绕过 .net 核心中的无效 SSL 证书

bypass invalid SSL certificate in .net core(绕过 .net 核心中的无效 SSL 证书)
本文介绍了绕过 .net 核心中的无效 SSL 证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个需要连接到 https 站点的项目.每次连接时,我的代码都会引发异常,因为该站点的证书来自不受信任的站点.有没有办法绕过 .net core http 中的证书检查?

I am working on a project that needs to connect to an https site. Every time I connect, my code throws exception because the certificate of that site comes from untrusted site. Is there a way to bypass certificate check in .net core http?

我在以前版本的 .NET 中看到了这段代码.我想我只需要这样的东西.

I saw this code from previous version of .NET. I guess I just need something like this.

 ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

推荐答案

.Net Core 不支持 ServicePointManager.ServerCertificateValidationCallback.

ServicePointManager.ServerCertificateValidationCallback isn't supported in .Net Core.

目前的情况是,这将是一个即将推出的 4.1.* System.Net.Http 合约 (HttpClient) 的新 ServerCertificateCustomValidationCallback 方法..NET Core 团队现在正在敲定 4.1 合同.您可以在 这里在 github

Current situation is that it will be a a new ServerCertificateCustomValidationCallback method for the upcoming 4.1.* System.Net.Http contract (HttpClient). .NET Core team are finalizing the 4.1 contract now. You can read about this in here on github

您可以直接在 CoreFx 或 MYGET 提要中使用源代码来试用 System.Net.Http 4.1 的预发布版本:https://dotnet.myget.org/gallery/dotnet-core

You can try out the pre-release version of System.Net.Http 4.1 by using the sources directly here in CoreFx or on the MYGET feed: https://dotnet.myget.org/gallery/dotnet-core

当前 WinHttpHandler.ServerCertificateCustomValidationCallback Github 上的定义

Current WinHttpHandler.ServerCertificateCustomValidationCallback definition on Github

这篇关于绕过 .net 核心中的无效 SSL 证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)