Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebClient().DownloadString() returning old data [duplicate]

Tags:

c#

php

webclient

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!

like image 506
Hussain Noor Mohamed Avatar asked Jul 14 '15 09:07

Hussain Noor Mohamed


1 Answers

Try disabling the cache on the WebClient

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

MSDN Documentation on WebClient Cache

like image 129
Equalsk Avatar answered Nov 01 '22 12:11

Equalsk