I have my Universal Windows Application and i want work with rest api. I always get error CS 4032 in this :
httpResponseBody = await httpClient.GetStringAsync(requestUri);
Like you can't call that method when it is not async.
Whole code
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Net;
using Windows.Web.Http;
namespace UniversalCA
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
Send();
}
public string Send()
{
HttpClient httpClient = new HttpClient();
Uri requestUri = new Uri("http://restapic.azurewebsites.net/WebForm1.aspx?func=dd&hodn=WW");
HttpResponseMessage httpResponse = new HttpResponseMessage();
string httpResponseBody = "";
try
{
httpResponseBody = await httpClient.GetStringAsync(requestUri);
}
catch (Exception ex)
{
httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message;
}
string tt = httpResponseBody.Split('>')[1].Split('<')[0];
return httpResponseBody;
}
}
}