Answered by:
The underlying connection was closed: The connection was closed unexpectedly

Question
-
Hello , i get this error message : The underlying connection was closed: The connection was closed unexpectedly at this code
try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://x.x.x.x:4042/admin.cgi?pass=test&mode=viewxml"); req.ContentType = "text/xml;charset=\"utf-8\""; req.Accept = "text/xml"; req.Method = "HEAD"; WebResponse resp = req.GetResponse(); StreamReader r = new StreamReader(resp.GetResponseStream()); richTextBox1.AppendText(r.ReadToEnd()+"\n"); } catch (System.Net.WebException webe) { richTextBox1.AppendText(webe.ToString() + "\n"); richTextBox1.AppendText(webe.Response.ToString() + "\n"); richTextBox1.AppendText(webe.Message.ToString()); }
can you help me ? thanks
- Edited by invader7 Tuesday, November 15, 2011 2:51 AM
Tuesday, November 15, 2011 2:50 AM
Answers
-
Hi Invader,
Try using these methods instead of StreamReader because i have seen that you are reading xml response.
XmlReader reader = XmlReader.Create(resp ); or
XmlTextReader reader=new XmlTextReader(resp );
Happy Coding
Thanks,
BR,
JollyWagoner
Please mark this as an answer if it solves your problem.
- Marked as answer by Michael Sun [MSFT]Microsoft employee Wednesday, November 23, 2011 1:52 AM
Tuesday, November 15, 2011 6:01 PM
All replies
-
There can be n number of reasons for this error. Try to follow these threads
Thanks,
A.m.a.L Hashim
Dot Net Goodies
Tuesday, November 15, 2011 3:03 AM -
thanks for replying , i tried the first link and didnot work , the second link its not visual C#Tuesday, November 15, 2011 12:51 PM
-
Hi Invader,
Try using these methods instead of StreamReader because i have seen that you are reading xml response.
XmlReader reader = XmlReader.Create(resp ); or
XmlTextReader reader=new XmlTextReader(resp );
Happy Coding
Thanks,
BR,
JollyWagoner
Please mark this as an answer if it solves your problem.
- Marked as answer by Michael Sun [MSFT]Microsoft employee Wednesday, November 23, 2011 1:52 AM
Tuesday, November 15, 2011 6:01 PM