C# WP8.1 HttpClient没有';在第一次请求后,不能下载字符串

C# WP8.1 HttpClient没有';在第一次请求后,不能下载字符串,c#,windows-phone-8.1,async-await,httpclient,C#,Windows Phone 8.1,Async Await,Httpclient,我想知道几天发生了什么事。我正在为WindowsPhone8.1编写一个应用程序,它使用HttpClient从Internet下载json字符串。它可以正常工作,但仅在运行应用程序后工作一次(在OnNavigatedTo事件中)。后来,粉碎本应再次下载字符串的“刷新”按钮不起作用。它仍然是与第一次下载时相同的字符串值。在服务器上,这个字符串会发生变化,我可以通过在PC的浏览器中查看它来确认这一点 using Newtonsoft.Json; using System; using System.

我想知道几天发生了什么事。我正在为WindowsPhone8.1编写一个应用程序,它使用HttpClient从Internet下载json字符串。它可以正常工作,但仅在运行应用程序后工作一次(在OnNavigatedTo事件中)。后来,粉碎本应再次下载字符串的“刷新”按钮不起作用。它仍然是与第一次下载时相同的字符串值。在服务器上,这个字符串会发生变化,我可以通过在PC的浏览器中查看它来确认这一点

using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace WP8App
{
    public sealed partial class MainPage : Page
    {
        private readonly Uri Website = new Uri("https://some-website.com/files/status.json");
        private HttpClient http = new HttpClient();

        public MainPage()
        {
            this.InitializeComponent();
            this.NavigationCacheMode = NavigationCacheMode.Required;
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Refresh();
        }

        private async void Button_Refresh_Click(object sender, RoutedEventArgs e)
        {
            Refresh();
        }

        private async void Refresh()
        {
            var response = await http.GetStringAsync(Website);
            JsonObject api = JsonConvert.DeserializeObject<JsonObject>(response);
            TextBox_A.Text = api.value;
            TextBox_B.Text = api.length;
            TextBox_C.Text = api.size;
            TextBox_F.Text = api.volume;
        }

        private async void ShowDialog(string value)
        {
            MessageDialog box = new MessageDialog(value);
            await box.ShowAsync();
        }
    }
}
使用Newtonsoft.Json;
使用制度;
使用System.Net.Http;
使用System.Threading.Tasks;
使用Windows.UI.Popups;
使用Windows.UI.Xaml;
使用Windows.UI.Xaml.Controls;
使用Windows.UI.Xaml.Navigation;
命名空间WP8App
{
公共密封部分类主页面:第页
{
私有只读Uri网站=新Uri(“https://some-website.com/files/status.json");
私有HttpClient http=新HttpClient();
公共主页()
{
this.InitializeComponent();
this.NavigationCacheMode=NavigationCacheMode.Required;
}
受保护的覆盖无效OnNavigatedTo(NavigationEventArgs e)
{
刷新();
}
私有异步无效按钮\u刷新\u单击(对象发送方,路由目标)
{
刷新();
}
私有异步无效刷新()
{
var response=wait http.GetStringAsync(网站);
JsonObject api=JsonConvert.DeserializeObject(响应);
TextBox_A.Text=api.value;
TextBox_B.Text=api.length;
TextBox_C.Text=api.size;
TextBox\u F.Text=api.volume;
}
专用异步void ShowDialog(字符串值)
{
MessageDialog box=新建MessageDialog(值);
wait box.ShowAsync();
}
}
}

我不是异步方面的高手,所以我依靠你的鹰眼xD感谢请求缓存在Windows Phone上非常具有攻击性。绕过它的最简单方法是在URL的末尾添加一个随机参数。比如:

private readonly string Website = "https://some-website.com/files/status.json?nocache={0}";
然后每次使用时都更改该值。使用当前时间戳是确保URL始终不同的一种既好又便宜的方法:

var response = await http.GetStringAsync(new Uri(string.Format(Website, DateTime.UtcNow.Ticks));

您是否尝试在
Refresh
方法中设置断点,以查看是否确实调用了该断点并返回了不同的值?请参阅