public RSS_Reader()
{
this.InitializeComponent();
}
public static async Task<string> DownloadPageAsync(string pageURL)
{
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync("http://www.parliament.uk/g/RSS/news-feed/?pageInstanceId=209&limit=20");
HttpContent content = response.Content;
string result = await content.ReadAsStringAsync();
return result;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var parameter = e.Parameter as string;
strURL = parameter.ToString();
Task<string> strXML = DownloadPageAsync(strURL);
ListBoxRss.Items.Add(strXML.Result);
}
我一直在制作的wp8应用程序的一部分。应用程序的主要登录页面链接到我从上面的代码中获取的第二页。第二页从未实际加载,只是挂在第一页上。
我做错了什么? 感谢。
答案 0 :(得分:1)
您应该使OnNavigatedTo
方法异步并等待DownloadPageAsync
方法:
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
var parameter = e.Parameter as string;
strURL = parameter.ToString();
string strXML = await DownloadPageAsync(strURL);
ListBoxRss.Items.Add(strXML);
}