G
Glenn
Hi
I'm trying to building something to check the availability of a web page.
The code is using a HttpWebRequest, bypassing our proxy server and hitting
both HTTP/HTTPS pages. Initially I get a HTTP response code of 200. After
the second or third attempt at hitting the same page over a period of a
couple of minutes, I get a timeout. Note that I'm creating a fresh
HttpWebRequest each time I hit the web page.
I restart the console app and it works, but again, only for a couple of
attempts.
Any ideas?
Thanks
Glenn
Code below...
public override bool RunTest()
{
bool success = false;
HttpWebRequest request = WebRequest.Create( WebSiteProperties.WebSiteUrl )
as HttpWebRequest;
request.CachePolicy = new HttpRequestCachePolicy(
HttpRequestCacheLevel.BypassCache );
try
{
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
HttpStatusCode responseHttpStatusCode = response.StatusCode;
List<string> expectedHttpStatusCodes = new List<string>(
WebSiteProperties.ExpectedHttpStatusCodes.Split( ",".ToCharArray(),
StringSplitOptions.RemoveEmptyEntries ) );
success = expectedHttpStatusCodes.Contains( (
(int)responseHttpStatusCode ).ToString() );
return success;
}
catch ( Exception exception )
{
return success;
}
}
I'm trying to building something to check the availability of a web page.
The code is using a HttpWebRequest, bypassing our proxy server and hitting
both HTTP/HTTPS pages. Initially I get a HTTP response code of 200. After
the second or third attempt at hitting the same page over a period of a
couple of minutes, I get a timeout. Note that I'm creating a fresh
HttpWebRequest each time I hit the web page.
I restart the console app and it works, but again, only for a couple of
attempts.
Any ideas?
Thanks
Glenn
Code below...
public override bool RunTest()
{
bool success = false;
HttpWebRequest request = WebRequest.Create( WebSiteProperties.WebSiteUrl )
as HttpWebRequest;
request.CachePolicy = new HttpRequestCachePolicy(
HttpRequestCacheLevel.BypassCache );
try
{
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
HttpStatusCode responseHttpStatusCode = response.StatusCode;
List<string> expectedHttpStatusCodes = new List<string>(
WebSiteProperties.ExpectedHttpStatusCodes.Split( ",".ToCharArray(),
StringSplitOptions.RemoveEmptyEntries ) );
success = expectedHttpStatusCodes.Contains( (
(int)responseHttpStatusCode ).ToString() );
return success;
}
catch ( Exception exception )
{
return success;
}
}