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;
}
标签:myHttpWebResponse,http,url,获取,result,false,winform,myHttpWebRequest 来源: https://www.cnblogs.com/lydj/p/15850556.html