Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I found some code for downloading the contents of a webpage, and it works great...in everything but XP SP2. For some reason it always throws an exception.

[CS]

public class CSDownloadURL

{

private string m_strURL;

public void setURL1( string strURL )

{

m_strURL = strURL;

}

 

public void DownloadURL(out string strContents)

{

WebRequest req = WebRequest.Create(m_strURL);

WebResponse res = req.GetResponse();

int iTotalBuff = 0;

Byte[] Buffer = new Byte[128];

Stream stream = res.GetResponseStream();

iTotalBuff = stream.Read(Buffer, 0, 128);

StringBuilder strRes = new StringBuilder("");

 

while(iTotalBuff != 0)

{

strRes.Append(Encoding.ASCII.GetString(Buffer, 0, iTotalBuff));

iTotalBuff = stream.Read(Buffer, 0, 128);

}

 

strContents = strRes.ToString();

 

}

 

}

[/CS]

 

Why would it work fine in everything but XP SP2 and windows 2003 server?

-Sean
Posted
Any chance of saying what exception and where it occurs?

Also have you considered that the XP firewall may be causing problems connecting?

 

The exception occurs when I ask it to download the source to a webpage, here is the exception text (I am unsure of which line as it does not error on my SP1 machine[development machine])

 

System.Net.WebException: The underlying connection was closed: The server

committed an HTTP protocol violation.

at System.Net.HttpWebRequest.CheckFinalStatus()

at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)

at System.Net.HttpWebRequest.GetResponse()

at webdownload.CSDownloadURL.DownloadURL(String& strContents)

at webdownload.Form1.button1_Click(Object sender, EventArgs e)

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)

 

 

Any ideas? I am definately going to check out firewall issue in SP2 though, great idea!

-Sean

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...