gpt4 book ai didi

c# - 如何忽略 SSL 证书是由未知证书颁发机构签署的问题?

转载 作者:太空狗 更新时间:2023-10-29 21:14:26 24 4
gpt4 key购买 nike

我正在开发 C# 应用程序来调用 Exchange Management Shell Cmdlet。它总是出现异常“目标计算机 (208.243.XX.2XX:443) 上的服务器证书有以下错误:
SSL 证书由未知的证书颁发机构签署。
SSL 证书包含与主机名不匹配的公用名 (CN)。 "

但是我确实写了接受所有证书的代码,不知道为什么仍然报错。

我的代码:

    PSCredential credential = new PSCredential("administrator", securePwd);

WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("https://208.243.49.20/powershell"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;

Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
PowerShell powershell = PowerShell.Create();
PSCommand command = new PSCommand();
command.AddCommand("New-Mailbox");
command.AddParameter("Name", "TestName");
powershell.Commands = command;
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(
delegate { return true; }
);
try
{
runspace.Open();//This is where the exception happens
powershell.Runspace = runspace;
Collection<PSObject> result= powershell.Invoke();
}

最佳答案

WSManConnectionInfo 对象有两个属性可以跳过证书检查。

connectionInfo.SkipCACheck = true;

connectionInfo.SkipCNCheck = true;

关于c# - 如何忽略 SSL 证书是由未知证书颁发机构签署的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6781433/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com