4

I'm trying to do something as simple as calling a REST API using an universal app for windows 10 IoT but I can't find a way to do it.

Normally I would use:

private XElement ImportData(string sourceUrl)
    {

        WebClient wc = new WebClient();

        String source = wc.DownloadString(sourceUrl);
        return XElement.Parse(source, LoadOptions.None);

    }

but it isn't available.

4

1 回答 1

4

you should use HttpClient instead of WebClient. Try this

HttpClient client = new HttpClient();
string url = "URL here";
HttpResponseMessage response = await client.GetAsync(url);
return response.Content.ReadAsString();
于 2015-05-12T05:08:13.467 回答