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

一个人想着一个人 提交于 2020-01-15 03:01:25

问题


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!


回答1:


Try disabling the cache on the WebClient

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

MSDN Documentation on WebClient Cache



来源:https://stackoverflow.com/questions/31403130/webclient-downloadstring-returning-old-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!