SpaceMonkey
SpaceMonkey

Reputation: 4365

HttpClient is caching requests to the same URL

On Xamarin iOS. I'm using HttpClient to get a JSON string. The problem is that it ignores updates and gives me the same JSON response if I query the same URL. I want it to not cache anything and always actually query the URL and give me the new response.

This sounds trivial, there must be a simple way for this. I'm using a Forms shared project.

Upvotes: 1

Views: 3686

Answers (1)

Keith Rome
Keith Rome

Reputation: 3228

I assume you are setting the cache-control header to no-cache? client.DefaultRequestHeaders.CacheControl.NoCache = true;

If so but it still doesn't work - maybe the server is caching the response? If it comes down to it, you can usually defeat something like that by adding a cachebuster to the querystring though. Just append a bogus param and pass it a unique value each time. For example, if your URL is http://my.url.com/resource/someid then you can defeat the caching by using http://my.url.com/resource/someid?b=1 and then increment that "b" param with each call.

Upvotes: 5

Related Questions