我想自动测试一长串网站是否可用。我需要在Intranet中测试某些网站的访问权限。我只需要基本上创建一个HTTPRequest并发送URL,然后读取HTTPResponse(200,404,500等)并记录结果。我已经有一些代码这样做,我得到了'OK'(200)的响应。它是否正确?还有什么我应该做的吗?
try
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(URL);
webRequest.Method = "GET";
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
System.Diagnostics.Debug.WriteLine("The response code is: " + webResponse.StatusCode);
System.Diagnostics.Debug.WriteLine("The response description is: " + webResponse.StatusDescription);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Catch: " + ex.Message);
}