问题描述
我正在使用此代码从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);
这篇关于WebClient().DownloadString()返回旧数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!