Hello I am trying to get the entire total page size with HttpWebRequest from images scripts etc. I need to calculate the total trafic of a web page if one user visits the page via web browser. The content length brings me the length of the content in byte size. It is actualy the document length. But i need to get all the traffic also from Images and scripts
This is my Code So far
NetworkCredential cred = new NetworkCredential("username", "password");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.Proxy = new System.Net.WebProxy("proxy", true);
request.Proxy.Credentials = cred;
request.UserAgent = @"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5";
using (HttpWebResponse requestresponse = (HttpWebResponse)request.GetResponse())
{
Headers = requestresponse.Headers;
Url = requestresponse.ResponseUri;
int ContentLength;
if (int.TryParse(response.Headers.Get("Content-Length"), out ContentLength))
{
//This is One way i get the content leangth
WebPageSize = ContentLength;
}
//This is another way i get the content leangth
WebPageSize = request.ContentLength;
return ProcessContent(requestresponse);
}
Also I the header content length is not guaranteed that the server will respond it back.
Any suggestions?
If you just need to check the size once why don’t you try using the Net panel of Firebug (Firefox extension) or the equivalent tool of other browsers? It will tell you the size off all the requests performed while loading a webpage.