I want to check if a particular page gets redirected or not. However, whenever I try this the headers I get back seem to be from the redirected page, not the initially requested page (and, in particular, the status is OK rather than the 302 I want to see).
Is there something I can set so that it won't automatically follow the redirects?
WebRequest request = WebRequest.Create(@"http://www.example.com/page.html");
request.Method = "HEAD";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.Redirect)
{
...
}
else
{
MessageBox.Show("HTTP Code: " + response.StatusCode + "\r\n\r\n" + response.StatusDescription);
return false;
}