我试图从HttpWebRequest返回的HttpWebResponse对象中获取HTTP状态码号码。我希望得到实际的数字(200,301,302,404等),而不是文本描述。(“Ok”,“movedpermanent”等)数字是否被埋在响应对象的某个属性中?除了创建一个大型开关函数,还有什么其他想法吗?谢谢。
HttpWebRequest webRequest = (HttpWebRequest)WebRequest
.Create("http://www.gooogle.com/");
webRequest.AllowAutoRedirect = false;
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
//Returns "MovedPermanently", not 301 which is what I want.
Console.Write(response.StatusCode.ToString());