Parallel HTTPRequest using HttpClient in a Windows 8 Application

I use HttpClient to send HTTP requests and receive HTTP responses in my Windows 8 application. I have a few questions about this:

1) Is it possible to send multiple / concurrent HTTP requests using a single HttpClient object? Is there a recommended way to efficiently use an HttpClient object?

2) What is the difference when I create an HttpClient object every time and when I reuse the same object for every new request?

3) I track requests and responses using Fiddler. I found out that the response time in Fiddler is different from the response time that I manually calculate in my application. The response time to a request in Fiddler is always less than the calculated response time in my application. Can someone please tell me why this is so?

4) Another thing that I came across is that for each request it does an HTTPS handshake. Instead, he should only do this for the first time. I tested it using Fiddler, and it is clearly visible there. Is there any property that I need to set in the HttpClient object so that this is not done every time.

5) Regardless of whether the HttpClient is thread safe?

+4
source share
2 answers

1 and 5:

HttpClient Guide :

The following methods are thread safe:

  • CancelPendingRequests
  • DeleteAsync
  • Getasync
  • GetByteArrayAsync
  • Getstreamasync
  • Getstringasync
  • Postasync
  • PutAsync
  • Sendasync

2 and 4:

HttpClient Guide :

An instance of the HttpClient class acts as a session to send HTTP requests.

3:

Fiddler acts as a proxy. Your browser sends a Fiddler request, which forwards it to the source server. This adds request time.

+3
source

Make sure you use the same HttpClient object for each asynchronous HttpRequest that will not allow it to overlap requests

+1
source

All Articles