I can't find how to replace Webclient from this code.
What's the new namespace and way to create it in Windows 8....new to Win 8 dev.
Any tips or posts would be helpful, or any code below.
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
Uri url2 = new Uri("http://www.buscms.com/api/XmlEntities/v1/stops.aspx", UriKind.Absolute);
client.DownloadStringAsync(url2);
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
if (e.Result != null)
{
XDocument doc = XDocument.Parse(e.Result);
XNamespace ns = "http://schemas.datacontract.org/2004/07/BusExpress.ClassLibrary";
var routeNames = (from n in doc.Descendants(ns + "ArrayOfStop")
select new RootContainer2
{
Departures = (from s in n.Elements(ns + "Stop")
select new Departures
{
StopName = s.Element(ns + "StopName").Value,
}).ToList()
}).Single();
listBox2.ItemsSource = routeNames.Departures;
}
}
}
You can use HTTPClient instead of WebClient, like this:
public async Task<string> DownloadTheString()
{
HttpClient http = new System.Net.Http.HttpClient();
HttpResponseMessage response = await http.GetAsync("http://www.buscms.com/api/XmlEntities/v1/stops.aspx");
string result = await response.Content.ReadAsStringAsync();
// Return the downloaded string
return result;
}
Here is another very similair question too: WebClient class doesn't exist in Windows 8
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.