I’m trying to measure a request with WebRequest,
But I’m getting significant smaller results then measuring with FireBug.
I guessing it’s because some content like Images and CSS isn’t included.
Is there a way to measure a full web request?
My code:
public string GetPageHtmlTime(string strUrl)
{
WebRequest request = null;
WebResponse response = null;
HttpWebResponse httpCurrentWeResponse = null;
try
{
//making a request to the file.
request = WebRequest.Create(strUrl);
//set 5 seconds timeout for the request
request.Timeout = 5 * 1000;
//Stopwatch
Stopwatch sw = new Stopwatch();
sw.Start();
//get the server response
response = request.GetResponse();
httpCurrentWeResponse = (HttpWebResponse)response;
sw.Stop();
//if the http response return any type of failure
if (httpCurrentWeResponse.StatusCode != HttpStatusCode.OK || response == null)
return "Error: " + httpCurrentWeResponse.StatusCode;
response.Close();
//Return time:
return "OK time=" + sw.ElapsedMilliseconds.ToString("0,0");
}
catch (System.Exception ex)
{
return "Error: ex=" + ex.Message;
}
}