【问题标题】:WebClient().DownloadString() returning old data [duplicate]WebClient().DownloadString() 返回旧数据[重复]
【发布时间】:2015-10-02 21:12:51
【问题描述】:

我正在使用此代码从 URL 获取返回字符串

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

code.php 看起来像这样

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

问题是当我更改code.txt 文件的内容时,webClient.DownloadString() 方法返回code.txt 文件的旧内容。当我在浏览器中打开 URL http://somesite.com/code.php 时,它工作得非常好。

任何解决方案将不胜感激!

我的问题似乎是重复的,但我不太明白这里说的是什么:C# WebClient disable cache

如果有人可以解释并提供一些示例代码,那就太好了!

【问题讨论】:

  • 我不太明白这个问题的答案。有示例代码吗?
  • 我提到的问题的答案中有很多有用的提示。您是否尝试过禁用webclient 中的缓存,甚至改用HttpWebRequest

标签: c# php webclient


【解决方案1】:

尝试禁用 WebClient 上的缓存

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

MSDN Documentation on WebClient Cache

【讨论】:

    猜你喜欢
    • 2012-06-02
    • 2013-11-03
    • 1970-01-01
    • 2020-11-27
    • 2020-06-30
    • 1970-01-01
    • 2023-04-05
    • 2017-11-23
    • 1970-01-01
    相关资源
    最近更新 更多