我的代码发出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);
}
Run Code Online (Sandbox Code Playgroud)
这段代码运行良好但突然抛出异常
Run Code Online (Sandbox Code Playgroud)System.Net.WebException异常消息是:基础连接已关闭:发送时发生意外错误.
堆栈跟踪:位于System.Net.HttpWebRequest.GetRequestStream(TransportContext&context)的System.Net.HttpWebRequest.GetRequestStream(),位于CustomerProcessor.Delivery.Deliver(String content,Int32 productCategory,String identifier,String xsltFile)
Exception有一个内部异常:发生异常:System.IO.IOException异常消息是:从传输流中收到意外的EOF或0字节.
堆栈跟踪:System.Net上的System.Net.FixedSizeReader.ReadPacket(Byte []缓冲区,Int32偏移量,Int32计数)处于System.Net的System.Net.Security.SslState.StartReadFrame(Byte []缓冲区,Int32 readBytes,AsyncProtocolRequest asyncRequest).在System.Net.Security.SslState.StartSendBlob(Byte []传入,Int32计数,System.SNet.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken消息,AsyncProtocolRequest asyncRequest)上的Security.SslState.StartReceiveBlob(Byte []缓冲区,AsyncProtocolRequest asyncRequest),位于System.Net.TlsStream.CallProcessAuthentication(对象状态)的System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)的System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst,Byte [] buffer,AsyncProtocolRequest asyncRequest)中的AsyncProtocolRequest asyncRequest) …