gpt4 book ai didi

c# - ServicePointManager.ServerCertificateValidationCallback 在 Windows Server 2012 R2 上不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 13:36:31 26 4
gpt4 key购买 nike

在我们的应用程序部署到我们的生产环境之前,我们从我们的 .NET Web 应用程序调用较低环境中的一些 API。那些托管 API 的服务器往往没有由受信任的证书颁发机构签署的证书。

我创建了以下代码作为解决方法,以安全的方式排除在我们的生产环境中运行此代码:

if (ignoreCertErrors && environmentName.ToLower() != "PROD")
{
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
}

ignoreCertErrors 和 environmentName 都是提供给包含此逻辑的方法的参数。

这适用于我的本地开发箱 (Windows 7),但是当我将它部署到 Windows 2012 R2 测试服务器时,我使用不受信任的证书调用 API 仍然失败并出现以下错误:

================================================================= Message: The underlying connection was closed: An unexpected error occurred on a send. Stack Trace:
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResultar)

================================================================= Message: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. Stack Trace:
at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)

================================================================= Message: An existing connection was forcibly closed by the remote host Stack Trace:
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)

=================================================================

我是否需要更改此逻辑,或执行一些新操作来忽略 Windows Server 2012 R2 上的证书警告?

最佳答案

我将以不同的方式处理这个问题,我创建了一个 question与错误消息相关,并寻求解决建议。

关于c# - ServicePointManager.ServerCertificateValidationCallback 在 Windows Server 2012 R2 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38384839/

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