4

I am using HttpClient for sending HTTP requests and receiving HTTP responses in my Windows 8 app. I have few questions on the same:

1) Can I send multiple/parallel HTTP requests using a single HttpClient object? Is there a recommended way to use HttpClient object efficiently?

2) What is the difference when I create HttpClient object every time and when I re-use the same object for each new request?

3) I am tracking the requests and responses using Fiddler. What I found out is that the response time in Fiddler is different than the response time I am calculating manually inside my App. The response time for a request in Fiddler is always lower than the calculated response time in my app. Can anybody please tell me why it is like that?

4) One more thing I came across is that for every request it is doing HTTPS handshake. Instead it should do it only first time. I checked it using Fiddler and it is clearly visible there. Is there any property I need to set in HttpClient object to stop this from doing it every time.

5) Whether HttpClient is thread-safe?

4

2 回答 2

3

1 & 5:

HttpClient 手册

以下方法是线程安全的:

  1. CancelPendingRequests
  2. 删除异步
  3. 获取异步
  4. GetByteArrayAsync
  5. 获取流异步
  6. 获取字符串异步
  7. 后异步
  8. PutAsync
  9. 发送异步

2 & 4:

HttpClient 手册

HttpClient 类实例充当发送 HTTP 请求的会话。

3:

Fiddler 充当代理。您的浏览器将请求发送到 Fiddler,Fiddler 将其转发到源服务器。这增加了请求时间。

于 2012-12-19T10:21:57.193 回答
1

确保为每个异步 HttpRequest 使用相同的 HttpClient 对象,这将防止它与请求重叠

于 2013-02-15T12:24:07.887 回答