Why does the HttpClient always give me the same response?

后端 未结 1 1097
忘掉有多难
忘掉有多难 2021-01-25 12:12

Environment:
VS2012 Update 4
Windows Phone 8 SDK
a fresh new Windows Phone project based on WP OS 7.1
NuGet pack1: MS Async
NuGet pack2: MS

相关标签:
1条回答
  • 2021-01-25 12:49

    It seems, you are hitting the same URL on every refresh click. Sometime Windows Phone stores the request and response in cache.

    If possible, you add one more parameter to your request and on every click just change the value of this parameter. You can use GUID or Unix Timestamp.

    You can try like:

     private async void RefreshJSONButton_Click(object sender, RoutedEventArgs e)
        {
            this.JsonView.Text = string.Empty;
            HttpClient client = new HttpClient();
        int unixTimestamp = (int)(DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
    
        string url =
        "http://API1 Address Here/Your queries&temp=unixTimestamp";
        string x = await client.GetStringAsync(url);
        this.JsonView.Text = x;
        client.Dispose();
        }
    
    0 讨论(0)
提交回复
热议问题