Greetings,
I have a problem with downloading a website to hard drive. I use code below and when I'm about to get answer I get an error:
The underlying connection was closed: The connection was closed unexpectedly.
I want to download that page to take from it data that I'm interested with.
Code:private void DownloadPage() { string url = "http://moneycentral.msn.com/scripts/webquote.dll"; string para = "Symbol=msft&getquote=Get+Quote"; string page = ""; try { HttpWebRequest PageRequest = (HttpWebRequest)WebRequest.Create(url); PageRequest.KeepAlive = true; PageRequest.Accept = "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1"; PageRequest.UserAgent = "Opera/9.64 (Windows NT 5.1; U; pl) Presto/2.1.1"; PageRequest.Method = WebRequestMethods.Http.Post; PageRequest.ContentType = "application/x-www-form-urlencoded"; PageRequest.ContentLength = para.Length; StreamWriter stOut = new StreamWriter(PageRequest.GetRequestStream(), System.Text.Encoding.ASCII); stOut.Write(para); stOut.Close(); WebResponse PageResponse = PageRequest.GetResponse(); // here is the error StreamReader stIn = new StreamReader(PageResponse.GetResponseStream()); page = stIn.ReadToEnd(); stIn.Close(); } catch (Exception Err) { MessageBox.Show(Err.Message); } }


Reply With Quote