In my .NET Standard project I'm using System.Net.Http.HttpClient
. How can I disable all caching (request caching especially) in HttpClient
?
If server sends responses with no cache header problem solves. But I want to make this on client side. I want to completely disable all caching.
Thanks.
Edit: It looks like I could use WebRequestHandler
but this does not exist in .NET standard. I can only use HttpClientHandler
but HttpClientHandler
doesn't have any option about caching.
You can use CacheControlHeaderValue in HttpClient
using System.Net.Http.Headers;
httpClient.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue
{
NoCache = true
}
For more information you can look https://docs.microsoft.com/en-us/dotnet/api/system.net.http.headers.cachecontrolheadervalue
I tried everything, this one worked for me. Just in case some is not able to make the accepted answer work:
var uri = new Uri("http://localhost:8080/v?time=" + DateTime.Now);
var client = new HttpClient();
var response = await client.GetAsync(uri);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With