views:

76

answers:

2

I am trying to measure how much data is sent and received by a HttpWebRequest (and Response).

As far as I can tell, it is only possible to know the length of the request and response content, in other words the body, not the header.

Does anyone know how to get the full length? Either header and body to be summed or possibly just a means of measuring all network IO from the thread or process?

A: 

Have you looked at the System.Net performance counters?

EDIT:

System.net already exposes perf counters for this. If you start "perfmon.exe" and go to the ".NET CLR Networking" category, you will see the following counters:

  1. Bytes Sent
  2. Bytes Received
  3. Connections established
  4. Datagrams Sent
  5. Datagrams Received

This should give you all that you need.

feroze
Not in great detail. Found http://blogs.msdn.com/b/ncl/archive/2009/08/07/new-performance-counters-for-httpwebrequest.aspx but still doesnt add what I need...
Paul Ridgway
A: 

sum up header & body may yield the answer you're looking for. measuring nio is not a recommended approach since it needs elevated privilege for your app & assembly; whenever possible an app & its assemblies should only use lowest security-level possible to perform the app's intent and no more. in elevated privilege scenario necessarily assumes you have god-access to the machine (root / domain admin / etc.).

ref 1: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.contentlength.aspx

ref 2: http://msdn.microsoft.com/en-us/library/system.net.webheadercollection.aspx

alien052002
Thanks for your response, it is a shame that there seems only such a crude method available. Unfortunately measuring the headers using the header collection wont get the initial PUT/GET/POST line. I know this seems trivial but accuracy is subjectively important when measuring...
Paul Ridgway