5

I am using this code to get the return string from URL

webClient.Encoding = Encoding.UTF8;
response = webClient.DownloadString("http://somesite.com/code.php");
Console.Write(response);

the code.php looks like this

<?php
$data = file_get_contents('code.txt');
echo $data;
?>

The problem is when I change the contents of the code.txt file, the webClient.DownloadString() method returns the old contents of the code.txt file. When I open the URL http://somesite.com/code.php in a browser it works perfectly fine.

Any solutions will be appreciated!

My question seems to be duplicated but I don't really understand what is said here: C# WebClient disable cache

If anyone could explain and provide some example code it would be great!

Community
  • 1
  • 1

1 Answers1

11

Try disabling the cache on the WebClient

webClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);

MSDN Documentation on WebClient Cache

Equalsk
  • 7,954
  • 2
  • 41
  • 67