我在windowsphone 8上遇到了关于webclient的问题。 我在我的代码上找到了一个API使用webclient。
public void LoadData(bool refresh)
{
IsLoading = true;
WebClient webclient = new WebClient();
webclient.DownloadStringCompleted += webclient_DownloadStringCompleted;
webclient.DownloadStringAsync(new Uri("http://api.xxxx.com/getQuestion"));
}
public void webclient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
RootObject deserCustomers = JsonConvert.DeserializeObject<RootObject>(e.Result);
foreach (var cust in deserCustomers.data)
{
Debug.WriteLine(cust.title);
int length = cust.question.Length;
string subquestion;
if (length > 100) { subquestion = cust.question.Substring(0, 100); }
else { subquestion = cust.question; }
_questiondata.Add(new QuestionItem() { Title = cust.title, Question_Str = subquestion, Slug = cust.slug });
}
IsLoading = false;
}
这是第一次工作,数据与网络完全相同。但是当网页更新时出现新问题,我尝试第二次调用方法LoadData,数据与web不一样。网络上的新更新问题没有出现在我的应用程序(Windows Phone)中。 我该怎么办,是否有任何缓存使我的结果不像网上那样更新?
非常感谢。
答案 0 :(得分:0)
我得到了一个帮助而且解决了。试试这个:
public void LoadData(bool refresh)
{
IsLoading = true;
WebClient webclient = new WebClient();
webclient.DownloadStringCompleted += webclient_DownloadStringCompleted;
Random random = new Random();
webclient.DownloadStringAsync(new Uri("http://api.xxxx.com/getQuestion?random="+ random.Next().ToString()));
}