Reputation: 244
I am trying to create a REST Client to measure the time taken for a HTTP Request to execute, that is to measure the time between the Client's request and the response from the server after it reaches the client.(There are other easier approaches to find this like fiddler etc, but I need this anyway). I am following Microsoft's example provided here:
https://msdn.microsoft.com/en-us/library/debx8sh9%28v=vs.110%29.aspx
should I just note the time when the response is returned?
// Send the request:
DateTime T = System.DateTime.UtcNow; //--> Note the initial Time
HttpWebResponse response = (HttpWebResponse) req.GetResponse();
TimeSpan TT = System.DateTime.UtcNow - T; //--> Note the Time Difference
or should I be calculating the time after the response stream is read:
DateTime T = System.DateTime.UtcNow;//--> Note the initial Time
HttpWebResponse response = (HttpWebResponse) req.GetResponse();
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
TimeSpan TT = System.DateTime.UtcNow - T;//--> Note the Time Difference
I am just not sure about the exact lines where the Request is made to the server and the Response from the Server are available to the Client.
Upvotes: 0
Views: 6861
Reputation: 4002
According to the msdn documentation, GetResponse()
will send the request to the server and retreive the response.
If you're just interested in timing the call, then the first option would be your best bet.
Upvotes: 1