WebClient.DownloadStringAsync URL not working

本文关键字:working not URL DownloadStringAsync WebClient | 更新日期: 2023-09-27 17:59:16

我在windowsphone 8上遇到了一个关于web客户端的问题。我在我的代码上找到了一个API使用Web客户端。

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

这是第一次工作,数据与网络完全相同。但是当web更新了新的问题,并且我第二次尝试调用方法LoadData时,数据与web不一样。网络上的新更新问题没有出现在我的应用程序(windowsphone)中。我该怎么办,是否有任何缓存使我的结果不会像在网上那样更新?

非常感谢。

WebClient.DownloadStringAsync URL not working

我得到了帮助,它已经解决了。试试这个:

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