我的代码进行HTTPS请求。 这是我的代码
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(UploadUrl);
request.Method = "POST";
request.KeepAlive = false;
request.Credentials = new NetworkCredential(userid, testpwd);
postData = "<root></root>";
request.ContentType = "application/x-www-form-urlencoded";
byte[] postDataBytes = Encoding.UTF8.GetBytes(postData);
request.ContentLength = postDataBytes.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(postDataBytes, 0, postDataBytes.Length);
requestStream.Close();
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
StreamReader responseReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
var result = responseReader.ReadToEnd();
responseReader.Close();
Console.WriteLine(result);
}
此代码是运行良好,但突然投掷以下异常
System.Net.WebException
异常消息为:基础连接已关闭:上一个发送发生意外的错误。
堆栈跟踪:在在System.Net.HttpWebRequest.GetRequestStream()System.Net.HttpWebRequest.GetRequestStream(TransportContext&上下文)在CustomerProcessor.Delivery.Deliver(字符串的内容,的Int32产品分类,字符串标识符,字符串xsltFile)
异常具有内异常:一个异常发生信息:System.IO.IOException异常消息是:收到从传输流意外EOF或0字节。
堆栈跟踪:在System.Net.FixedSizeReader.ReadPacket(字节[]缓冲液,的Int32偏移的Int32计数)在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.runTryCode(对象的UserData)在System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode代码,CleanupCode backoutCode, 对象的UserData)在System.Threading.ExecutionContext.RunInternal(的ExecutionContext的ExecutionContext,ContextCallback回调,对象状态)在System.Threading.ExecutionContext.Run(的ExecutionContext的ExecutionContext,ContextCallback回调,在System.Net.TlsStream.ProcessAuthentication对象状态)(LazyAsyncResult结果)
在System.Net.TlsStream.Write(字节[]缓冲液,的Int32偏移的Int32大小)在System.Net.PooledStream.Write(字节[]缓冲液,的Int32偏移的Int32大小)在System.Net.ConnectStream.WriteHeaders(布尔异步)
是否有机会,看看有什么可能是这个问题的原因是什么?