Ali R.
Ali R.

Reputation: 49

HttpClient.PostAsync takes twice as long as actual latency?

This is a windows form application. I am using stop watch to measure the time of this operation:

HttpResponseMessage response = await httpClient.PostAsync(EndPoint, stringContent);

It comes out to be 600-700 ms. The latency to the web service is ~250 ms. I checked with fiddler and the request is taking <300 ms. So my question is why is there an extra 300-400 ms?

Upvotes: 2

Views: 914

Answers (1)

Saeb Amini
Saeb Amini

Reputation: 24449

You have to take the round-trip into account. Your code has 2 parts:

  • Sending the request, sent from you to the web service.
  • Reading the response, sent from the web service to you.

So your request is still taking ~300ms, but so is the response and that's why the whole thing is taking about 2x your latency.

Upvotes: 1

Related Questions