【发布时间】:2013-03-21 10:49:58
【问题描述】:
我正在尝试编写一个重定向检查器,我的解决方案今天早上刚刚组合在一起,所以它不是最有效的,但它可以完成我需要它做的所有事情,除了一件事:
它在停止之前只检查两个站点,没有发生错误,它只是在“request.GetResponse() as HttpWebResponse;”上停止第三页的行。
我尝试使用不同的网站并更改要检查的页面组合,但它只检查两个。
有什么想法吗?
string URLs = "/htmldom/default.asp/htmldom/dom_intro.asp/htmldom/dom_examples2.asp/xpath/default.asp";
string sURL = "http://www.w3schools.com/";
string[] u = Regex.Split(URLs, ".asp");
foreach (String site in u)
{
String superURL = sURL + site + ".asp";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(superURL);
request.Method = "HEAD";
request.AllowAutoRedirect = false;
var response = request.GetResponse() as HttpWebResponse;
String a = response.GetResponseHeader("Location");
Console.WriteLine("Site: " + site + "\nResponse Type: " + response.StatusCode + "\nRedirect page" + a + "\n\n");
}
【问题讨论】:
标签: c# redirect httpwebrequest httpwebresponse