WebClient error

Y

yyy

This problem bothers me for a long time:
I use WebClient.DownloadData in order to read text from an HTML
document this way:

WebClient c = new WebClient();
string html=
ASCIIEncoding.Default.GetString(c.DownloadData("http://www.test.com"));

When I run the code, I get this error message after a few seconds:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Net.WebException: The underlying connection was closed:
Unable to connect to the remote server.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
at System.Net.WebClient.DownloadData(String address)
at RE.MainForm.Button1Click(Object sender, EventArgs e) in
c:\Documents and Settings\Y\My Documents\SharpDevelop
Projects\RE\MainForm.cs:line 93
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)

What can I do to solve it? It worked once and stopped working a few
months ago.
 
G

Guest

I met the same error when the web site return 500 error.
Try to access the HTML document with ie, hope this be helpful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top