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

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

问题描述

使用 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 = 凭证;request.CookieContainer = cookieContainer;var response = request.GetResponse();

<块引用>

异常:System.Net.WebException:底层连接是关闭:发送时发生意外错误.--->System.IO.IOException:身份验证失败,因为远程方已关闭传输流.在System.Net.Security.SslState.StartReadFrame(字节 [] 缓冲区,Int32readBytes,AsyncProtocolRequest asyncRequest)在System.Net.Security.SslState.StartReceiveBlob(字节 [] 缓冲区,AsyncProtocolRequest asyncRequest) 在System.Net.Security.SslState.CheckCompletionBeforeNextReceive(协议令牌消息,AsyncProtocolRequest asyncRequest)在System.Net.Security.SslState.StartSendBlob(字节 [] 传入,Int32计数,AsyncProtocolRequest asyncRequest)在System.Net.Security.SslState.ForceAuthentication(布尔接收第一,Byte[] 缓冲区,AsyncProtocolRequest asyncRequest) 在System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResultlazyResult) 在 System.Net.TlsStream.CallProcessAuthentication(Object州)在System.Threading.ExecutionContext.RunInternal(ExecutionContextexecutionContext、ContextCallback 回调、对象状态、布尔值preserveSyncCtx) 在System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext、ContextCallback 回调、对象状态、布尔值preserveSyncCtx) 在System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext、ContextCallback 回调、对象状态)在System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult 结果)在System.Net.TlsStream.Write(Byte[] 缓冲区,Int32 偏移量,Int32 大小) 在System.Net.PooledStream.Write(Byte[] 缓冲区,Int32 偏移量,Int32 大小)在 System.Net.ConnectStream.WriteHeaders(Boolean async) --- 结束内部异常堆栈跟踪 --- 在System.Net.HttpWebRequest.GetResponse()

提前致谢.

解决方案

我只想分享这个问题已经解决了.

我只是在发出网络请求之前修改了设置安全协议的代码部分.

发件人:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

收件人:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 |安全协议类型.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天全站免登陆