使用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();
异常: System.Net.WebException:基础连接被关闭:在发送时发生意外错误。 ---> System.IO.IOException:由于远程方已关闭传输流而导致身份验证失败。在System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)处
开始读取帧,在System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)处开始接收Blob,在System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)处检查完成下一个接收之前的协议令牌消息,在System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)处开始发送Blob,在System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)处强制进行身份验证,在System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)处处理身份验证,在System.Net.TlsStream.CallProcessAuthentication(Object state)处调用ProcessAuthentication,在System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)处运行内部线程上下文,在System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)处执行线程上下文,在System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)处运行上下文,在System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)处处理身份验证,在System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)处写入字节,在System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)处写入字节,在System.Net.ConnectStream.WriteHeaders(Boolean async)处写入标头。--- 内部异常堆栈跟踪结束 --- 在System.Net.HttpWebRequest.GetResponse()处抛出此异常。谢谢!