【问题标题】:Can HTTP requests be unintentionally cached?HTTP 请求会被无意缓存吗?
【发布时间】:2014-04-29 21:41:56
【问题描述】:
以下 HTTP 提取应返回字符串 262。对于我的一些用户(但不是全部,甚至大多数)来说,它似乎返回了一个较旧的值261。
string latestVersion = new System.Net.WebClient().DownloadString(
"http://www.pixelchampions.com/latest.txt");
我真的不知道为什么。 IIS7 主要使用默认设置。某些路由器/ISP 是否会缓存非查询 HTTP 请求的结果?
【问题讨论】:
标签:
c#
http
caching
networking
【解决方案1】:
您可以试试这个(或其他 RequestCacheLevel 设置之一):
WebClient MyClient = new System.Net.WebClient() ;
MyClient.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
string latestVersion = MyClient.DownloadString(
"http://www.pixelchampions.com/latest.txt");