您可以尝试禁用重定向,不幸的是我无法测试它,因为我有另一个提供商(如果这是问题的话)。
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.goo4le.com/");
request.Method = "HEAD";
request.AllowAutoRedirect = false;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
Console.Write((int)response.StatusCode);
}
如果它正在工作,它很可能会抛出一个异常,因为所有返回不是 200 的状态码的东西都会抛出一个......如果你想抓住它,试试这个:
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.goo4le.com/");
request.Method = "HEAD";
request.AllowAutoRedirect = false;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
Console.Write((int)response.StatusCode);
}
}
catch (WebException e)
{
// in this case it was a status code exception (not status 200...)
if (e.Response != null) Console.Write((int)e.Response.StatusCode);
else throw;
}