Windows 8.1通用应用程序WebClient替代

本文关键字:WebClient 替代 应用程序 1通 Windows | 更新日期: 2023-09-27 18:25:59

我正在将Win8应用程序迁移到Win通用应用程序,我需要替换以下代码:

WebClient wc = new WebClient();                
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
wc.DownloadStringAsync(new Uri(URL));

问题是,WebClient似乎已被弃用,并且在通用应用程序中不再受支持。有人向我推荐了HttpClient,但它没有合适的属性。有什么兼容的类我可以使用吗?

Windows 8.1通用应用程序WebClient替代

我找到的唯一方法是使用HttpClient类。然后手动检查并处理响应消息。

试试这个:

HttpClient client = new HttpClient(); 
string ResponceResult= await client.GetStringAsync(new Uri("http://example.com/datalist.aspx"));  

使用WebView

WebView wView;
wView.Navigate(new URI("page"))
wView.NavigationCompleted += new EventHandler(...)
wView.NavigationStarting  += new EventHandler(...)