请求URL获取状态
请求URL获取URL状态的代码
不足之处,请大家指正....................
public static HttpStatusCode GetHttpWebRequestStatusCode(string urlAddress)
{
try
{
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(urlAddress);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
myHttpWebResponse.Close();
return myHttpWebResponse.StatusCode;
}
catch (WebException e)
{
if (e.Status == WebExceptionStatus.ProtocolError)
{
return ((HttpWebResponse) e.Response).StatusCode;
}
}
catch (Exception e)
{
return HttpStatusCode.SeeOther;
}
return HttpStatusCode.SeeOther;
}
可以用来获取服务器的服务状态{
try
{
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(urlAddress);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
myHttpWebResponse.Close();
return myHttpWebResponse.StatusCode;
}
catch (WebException e)
{
if (e.Status == WebExceptionStatus.ProtocolError)
{
return ((HttpWebResponse) e.Response).StatusCode;
}
}
catch (Exception e)
{
return HttpStatusCode.SeeOther;
}
return HttpStatusCode.SeeOther;
}
不足之处,请大家指正....................