Ошибка веб-публикации "запрос был прерван: запрос был отменен."
код:
req = System.Net.WebRequest.Create(uri); req.Credentials = System.Net.CredentialCache.DefaultCredentials; req.Proxy.Credentials = CredentialCache.DefaultCredentials; req.Method = "POST"; req.Timeout = 2139999999; req.ContentType = "text/xml"; string text = XMLString;//Xml string req.ContentLength = text.Length + 1000; System.IO.StreamWriter writer = new System.IO.StreamWriter(req.GetRequestStream()); writer.WriteLine(text); writer.Close(); rsp = req.GetResponse(); System.IO.StreamReader reader = new System.IO.StreamReader(rsp.GetResponseStream()); string rp = reader.ReadToEnd(); reader.Close();
верните мне веб исключение:
System.Net.WebException was caught Message=The request was aborted: The request was canceled. Source=System StackTrace: at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting) at System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState closeState) at System.Net.ConnectStream.Dispose(Boolean disposing) at System.IO.Stream.Close() at Ping.FormPostType(String uri, String buyerid) in c:\Inetpub\wwwroot\TestIceBlue\Ping.aspx.cs:line 545 at Ping.FirstTask(String i, String uri, String buyerid, String PostT, String ResponseT) in c:\Inetpub\wwwroot\TestIceBlue\Ping.aspx.cs:line 325 InnerException: System.IO.IOException Message=Cannot close stream until all bytes are written. Source=System StackTrace: at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting)
Пожалуйста, помогите, как я могу разрешить это исключение?
Я также пытаюсь использовать приведенный ниже код, но все равно он выдает мне ошибку "запрос был прерван: запрос был отменен.":
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(uri); Request.Credentials = System.Net.CredentialCache.DefaultCredentials; Request.Proxy.Credentials = CredentialCache.DefaultCredentials; Request.Timeout = 2139999999; Request.Method = "POST"; Request.ContentType = "application/x-www-form-urlencoded"; ASCIIEncoding AscTest = new ASCIIEncoding(); Byte[] PostData = AscTest.GetBytes(sQryString); Request.ContentLength = PostData.Length + 1000; Request.KeepAlive = false; System.IO.Stream RequestStream = Request.GetRequestStream(); RequestStream.Write(PostData, 0, PostData.Length); RequestStream.Close(); System.IO.StreamReader Reader = new StreamReader(Request.GetResponse().GetResponseStream()); String ResultHTML = Reader.ReadToEnd();
Dalek Dave
Отредактировано для блока кода.