在失败与HttpWebRequest的内部异常验证失败,因为远程方已关闭传输流 [英] Failure on HttpWebrequest with inner exception Authentication failed because the remote party has closed the transport stream

查看:2324
本文介绍了在失败与HttpWebRequest的内部异常验证失败,因为远程方已关闭传输流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C#,.NET 4.5,我想发出HttpWebRequest的通过Web请求的远程服务器上。请参阅下面的code。
我试图最受一些论坛上提出的解决方案,但我总是相同的错误结束。请参考下面的堆栈跟踪。
调用request.GetReponse()方法时,引发错误。

附加信息,基本上,我试图调用安装在远程服务器上的VMware的vCenter组件的reloadSslCertificate功能。目前,该错误仅发生在vCenter上5.5。它工作正常,在5.1及以下版本。

  VAR URI =的String.Format(https://开头{0} / SOME_URL,服务器名);
        VAR请求=(HttpWebRequest的)WebRequest.Create(URI);
        request.KeepAlive = TRUE;
        request.Accept =text / html的,是application / xhtml + xml的,应用/ XML; Q = 0.9 * / *; Q = 0.8;
        request.Headers.Set(HTT prequestHeader.AcceptLanguage,EN-US,连接; Q = 0.8);
        request.Credentials =凭证;
        request.CookieContainer =的CookieContainer;
        变种响应= request.GetResponse();


  

异常:System.Net.WebException:基础连接已
  关闭:一个发送发生意外的错误。 --->
  System.IO.IOException:身份验证失败,因为远程方
  已关闭传输流。在
  System.Net.Security.SslState.StartReadFrame(字节[]缓冲区的Int32
  的ReadBytes,AsyncProtocolRequest asyncRequest)在
  System.Net.Security.SslState.StartReceiveBlob(字节[]缓冲区,
  AsyncProtocolRequest asyncRequest)在
  System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken
  消息AsyncProtocolRequest asyncRequest)在
  System.Net.Security.SslState.StartSendBlob(字节[]来电,的Int32
  算,AsyncProtocolRequest asyncRequest)在
  System.Net.Security.SslState.ForceAuthentication(布尔receiveFirst,
  字节[]缓冲区,AsyncProtocolRequest asyncRequest)在
  System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult
  lazyResult)在System.Net.TlsStream.CallProcessAuthentication(对象
  状态)的
  System.Threading.ExecutionContext.RunInternal(执行上下文
  ExecutionContext中,ContextCallback回调,对象的状态,布尔
  preserveSyncCtx)的
  System.Threading.ExecutionContext.Run(执行上下文
  ExecutionContext中,ContextCallback回调,对象的状态,布尔
  preserveSyncCtx)的
  System.Threading.ExecutionContext.Run(执行上下文
  ExecutionContext中,ContextCallback回调,对象状态)在
  System.Net.TlsStream.ProcessAuthentication在(LazyAsyncResult结果)
  System.Net.TlsStream.Write(字节[]缓冲区,偏移的Int32,的Int32大小)在
  System.Net.PooledStream.Write(字节[]缓冲区,偏移的Int32,的Int32大小)
  在System.Net.ConnectStream.WriteHeaders(布尔异步)---结束
  内部异常堆栈跟踪---在
  System.Net.HttpWebRequest.GetResponse()


先谢谢了。


解决方案

我想和大家分享,这个问题已经得到解决。

我只是修改了code,我发出Web请求之前设置的安全协议的一部分。

从:

  ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

要:

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

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

Using C#, .Net 4.5, I'm trying to send out a web request through HttpWebRequest on a remote server. Please see the code below. I tried most of the solutions suggested by some forums but I always end up with the same error. Please see the stack trace below. The error is thrown when calling the request.GetReponse() method.

Additional info, basically, I'm trying to call the reloadSslCertificate function of vmware's vCenter component installed on a remote server. Currently, the error only happens on vCenter 5.5. It works fine in versions 5.1 and below.

        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()

Thanks in advance.

解决方案

I just want to share that this issue has already been resolved.

I just modified the part of the code where I set the security protocol before issuing the web request.

From:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

To:

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

As it turned out, vCenter 5.5 uses TLS as its SSL protocol in its configuration. I hope people may find this helpful when they encounter this same issue.

这篇关于在失败与HttpWebRequest的内部异常验证失败,因为远程方已关闭传输流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆