404 - the path to the birth. The code provided in the answer in your link ( fooobar.com/questions/112569 / ... ) does not handle errors - this is a vivid example of how you may encounter problems when blindly copying code from stackoverflow :)
The modified error-handling code should look like this:
string urlAddress = "http://google.com/rrr"; var request = (HttpWebRequest)WebRequest.Create(urlAddress); string data = null; string errorData = null; try { using (var response = (HttpWebResponse)request.GetResponse()) { data = ReadResponse(response); } } catch (WebException exception) { using (var response = (HttpWebResponse)exception.Response) { errorData = ReadResponse(response); } } static string ReadResponse(HttpWebResponse response) { if (response.CharacterSet == null) { using (var reader = new StreamReader(response.GetResponseStream())) { return reader.ReadToEnd(); } } using (var reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(response.CharacterSet))) { return reader.ReadToEnd(); } }
So, when there is an exception, you will get not only the status code, but the whole response from the server in the errorData variable.
One thing to check is a proxy browser can use HTTP proxies until your client server uses one.
source share