Search code examples
c#http-getiotwindows-10-iot-corewindowsiot

how create get url from Visual Studio 2015 for Windows Iot in app C#


How create get url from Visual Studio 2015 for Windows Iot in app C# (Universal App Windows)

Getreponse(); from c# 2015 is deprecated

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://XXX/online?check=useronline");
request.Method = "GET";
using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
using (var reader = new StreamReader(stream))

enter image description here


Solution

  • Universal App Platform has a great class for HTTP.

    HttpClient has all you need to get a web resource with a very few lines of code.

    var client = new HttpClient();
    var content = await client.GetStringAsync(new Uri("http://danvy.tv"));
    

    Check the details here

    https://msdn.microsoft.com/en-US/library/windows/apps/xaml/windows.web.http.httpclient.getstringasync