标签:style blog http io ar color os sp div
public static void GetHead(string url) { var http = (HttpWebRequest)WebRequest.Create(url); http.Method = "HEAD";//设置Method为HEAD http.UserAgent = "Tujia-Auto-Test"; try { HttpWebResponse response = (HttpWebResponse)http.GetResponse(); Console.Write(Convert.ToInt32(response.StatusCode) + " " + response.StatusCode.ToString());//Statuscode 为枚举类型,200为正常,其他输出异常,需要转为int型才会输出状态码 response.Close(); } catch (WebException ex) { Console.WriteLine(Convert.ToInt32(((HttpWebResponse)ex.Response).StatusCode)+" "+((HttpWebResponse)ex.Response).StatusCode.ToString()); } }
可以将 Method 属性设置为任何 HTTP 1.1 协议谓词:GET、HEAD、POST、PUT、DELETE、TRACE 或 OPTIONS。
标签:style blog http io ar color os sp div
原文地址:http://www.cnblogs.com/techfans/p/4106373.html