The reason why a request is performed only once here is because by default, HttpClient
uses a cache to store responses according to received Cache-Control
headers (similar to HTTPClient Caching in .Net). There are two ways to work around it.
The easiest solution is to use HttpBaseProtocolFilter.CacheControl.ReadBehavior
property to handle cases when you want to skip the cache:
var httpFilter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
httpFilter.CacheControl.ReadBehavior =
Windows.Web.Http.Filters.HttpCacheReadBehavior.MostRecent;
var httpClient = new Windows.Web.Http.HttpClient(httpFilter);
However, a solution I consider cleaner is to modify your server so it includes the appropriate headers that tell browsers do not cache the response, i.e.:
Cache-Control: no-cache
E.g.:
HTTP/1.1 200 OK
Content-Length: 31
Content-Type: text/plain; charset=UTF-8
Cache-Control: no-cache
...
The second solution has two advantages:
- A content you will not use again is not stored in the client machine.
- Other requests can benefit from the cache (when using the same instance of
HttpClient
).