Quite probably due to your Proxy configuration / firewall blocking.
On May 6, 2:44 pm, cspaceman <[email protected]> wrote: > Hi, > > Pretty new to c# / .NET - apologies in advance if this is obvious or > trivial. > > I'm trying to save webpages (testcode with google.com) using the code > shown below (mostly cobbled together from various places). On the > line > > strm = Client.OpenRead("http://www.google.com"); > > An error is raised: > > "An unhandled exception of type 'System.Net.WebException' occurred in > System.dll > > Additional information: Unable to connect to the remote server" > > Could anyone shine some light on why this mght be happening. I'm > working behind a corporate firewall in case that makes any > difference. > > Full code: > > public Form1() > { > InitializeComponent(); > > string line; > Stream strm; > WebClient Client; > StreamReader sr; > WebProxy proxy; > > proxy = new WebProxy("**.***.***.***:8080"); > proxy.Credentials = CredentialCache.DefaultCredentials; > proxy.Credentials = new NetworkCredential(<userID>, > <myPassword>); > GlobalProxySelection.Select = proxy; > > Client = new WebClient(); > Client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; > MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); > strm = Client.OpenRead("http://www.google.com"); > sr = new StreamReader(strm); > > do > { > line = sr.ReadLine(); > listBox1.Items.Add(line); > } > while (line != null); > strm.Close(); > > } > > Many thanks, > > Chris
