The actual exception is probably an IOException
- you would need to catch that exception type as well as WebException
. The actual problem may be that your URL is out of date and the system is no longer running a web server, or perhaps, the request needs to be authenticated/needs a header as @L.B suggests.
Also, you are potentially leaking all sorts of resources. You should be wrapping your WebResponse and streams in using
statements.
using (var response = (HttpWebResponse)request.GetResponse())
using (var receiveStream = response.GetResponseStream())
using (var reader = new StreamReader(receiveStream))
{
var content = reader.ReadToEnd();
// parse your content, etc.
}