winform,获取http服务状态

/// <summary>
/// 获取http服务状态
/// </summary>
/// <returns></returns>
protected static bool CheckPageUrl()
{
String url = "http://*:7000/posttype/";//获取本地ip地址+端口号
bool result = false;
try
{
if (url.IndexOf("http").Equals(-1))
{

}
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
myHttpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko";
myHttpWebRequest.Method = "GET";
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
{
result = true;
}
myHttpWebResponse.Close();
}
catch
{
result = false;
}
return result;
}

上一篇:一个无聊的python + opencv 示例


下一篇:informatica中的workflow连接远程数据库