coldfusion244 Posted January 25, 2005 Posted January 25, 2005 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? Quote -Sean
Administrators PlausiblyDamp Posted January 25, 2005 Administrators Posted January 25, 2005 Any chance of saying what exception and where it occurs? Also have you considered that the XP firewall may be causing problems connecting? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
coldfusion244 Posted January 25, 2005 Author Posted January 25, 2005 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! Quote -Sean
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.