WebClient().DownloadString()返回旧数据 [英] WebClient().DownloadString() returning old data

查看:143
本文介绍了WebClient().DownloadString()返回旧数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

code.php看起来像这样

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

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

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!

我的问题似乎重复了,但我不太理解这里所说的内容: C# WebClient禁用缓存

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!

推荐答案

尝试在WebClient上禁用缓存

Try disabling the cache on the WebClient

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

MSDN文档在WebClient缓存上

这篇关于WebClient().DownloadString()返回旧数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆