c# - HttpWebrequest 失败,内部异常身份验证失败,因为远程方已关闭传输流

标签 c# ssl-certificate vmware vcenter system.net.webexception

使用 C#、.Net 4.5,我试图通过远程服务器上的 HttpWebRequest 发送 Web 请求。请看下面的代码。 我尝试了一些论坛建议的大部分解决方案,但我总是以同样的错误告终。请参阅下面的堆栈跟踪。 调用 request.GetReponse() 方法时抛出错误。

附加信息,基本上,我正在尝试调用安装在远程服务器上的 vmware vCenter 组件的 reloadSslCertificate 函数。目前,该错误仅发生在 vCenter 5.5 上。它在 5.1 及以下版本中运行良好。

        var uri = String.Format("https://{0}/some_url", serverName);
        var request = (HttpWebRequest)WebRequest.Create(uri);
        request.KeepAlive = true;
        request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        request.Headers.Set(HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.8");
        request.Credentials = credential;
        request.CookieContainer = cookieContainer;


        var response = request.GetResponse();

Exception : System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Authentication failed because the remote party has closed the transport stream. at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) at System.Net.TlsStream.CallProcessAuthentication(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) at System.Net.ConnectStream.WriteHeaders(Boolean async) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetResponse()

提前致谢。

最佳答案

我只是想告诉大家这个问题已经解决了。

我刚刚修改了在发出网络请求之前设置安全协议(protocol)的代码部分。

来自:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

收件人:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;

事实证明,vCenter 5.5 在其配置中使用 TLS 作为其 SSL 协议(protocol)。我希望人们遇到同样的问题时会发现这对他们有所帮助。

关于c# - HttpWebrequest 失败,内部异常身份验证失败,因为远程方已关闭传输流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19639846/

相关文章:

ubuntu - 适用于 Ubuntu Hardy 的 VMWare 工具

c# - 实现存储库模式的删除方法

c# - C# 中字符串的最大大小是多少?

c# - 从 ThreadID 获取 ThreadName

ssl - 如何在 IIS 上安装从 SSLForFree.com 收到的 ssl 证书

ssl - 使用VS2015作为本地实例将开发ssl证书绑定(bind)到IP地址

linux - 虚拟机之间的一种方式通信?

c# - 夜间检查功能 c#

ssl-certificate - java程序的自签名证书

delphi - 确定何时在虚拟机中运行