我有以下几点:
HttpWebRequest webRequest = HttpWebRequest)WebRequest.Create("http://www.google.com/");
webRequest.AllowAutoRedirect = false;
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
HttpStatusCode wRespStatusCode = new HttpStatusCode();
try
{
response = (HttpWebResponse)webRequest.GetResponse();
wRespStatusCode = response.StatusCode;
}
catch (WebException we)
{
wRespStatusCode = ((HttpWebResponse)we.Response).StatusCode;
}
MessageBox.Show(wRespStatusCode.ToString());
获取HTTP请求的状态代码。
如果是301“永久移动”响应,我想知道如何找到请求被重定向到的新URL?
答案 0 :(得分:3)
如301 status code section in the HTTP specification所示,请查看Location
标题,可从HttpWebResponse.Headers
媒体资源中访问。