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.

Hemadeus
  • 472
  • 8
  • 20

1 Answers1

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();
Kashif
  • 2,926
  • 4
  • 20
  • 20
  • 1
    I have a post here that details calling a REST service with HttpClient:http://blogs.msdn.com/b/wsdevsol/archive/2013/02/05/how-to-use-httpclient-to-post-json-data.aspx – Jeff Sanders - MSFT May 12 '15 at 21:04
  • do you have an example for Put as the code I have does not work. http://stackoverflow.com/questions/33464906/why-does-my-web-api-client-call-not-work-in-raspberry-pi2-iot – Andrew Simpson Nov 01 '15 at 17:43