[英]C# downloading page returns old page
I have problem, i wrote method to get current song on Czech radio. 我遇到了问题,我写了一种方法来在捷克广播电台获取当前歌曲。 They do not have API so i had to get song from html via html agility.dll Problem is even though song title changes on page my method downloads old page, usually i have to wait like 20 seconds and have my app closed, then it works.
他们没有API,因此我不得不通过html agility.dll从html获取歌曲问题是即使页面上的歌曲标题发生了更改,我的方法也下载了旧页面,通常我必须等待20秒并关闭我的应用程序,然后它才能工作。 I thought some cache problem, but i could not fix it.
我认为某些缓存问题,但无法解决。 tried: DownloadString method did not refresh either.
尝试过:DownloadString方法也未刷新。
public static string[] GetEV2Songs()
{
List<string> songy = new List<string>();
string urlAddress = "http://www.evropa2.cz/";
string data = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = null;
if (response.CharacterSet == null)
readStream = new StreamReader(receiveStream);
else
readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
data = readStream.ReadToEnd();
response.Close();
readStream.Close();
}
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(data);
string temp = "";
foreach (var node in doc.DocumentNode.SelectNodes("//body//h2"))
{
if (node.InnerText.Contains("&ndash"))
{
temp = node.InnerText.Replace("–", "-");
songy.Add(temp);
}
}
return songy.ToArray();
}
Sounds like being a caching problem. 听起来像是一个缓存问题。 Try to replace the 4th line with something like that:
尝试用类似以下内容替换第四行:
string urlAddress = "http://www.evropa2.cz/?_=" + System.Guid.NewGuid().ToString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.