Ok so I have a website created in ASP.NET Web applications (web forms) and UWP app. I have a gridview webform page in my website. I want this gridview to be retrieved to my UWP app. Currently, I've tried to use HTTP Client service which i'm also not too sure how it works tbh. I'm actually very confused with coding ;) i'm very new to programming :)
Ad.xaml:
<Page
x:Class="TMD_Display.Views.Ad"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TMD_Display.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="using:TMD_Display.Models"
xmlns:fileproperties="using:Windows.Storage.FileProperties"
mc:Ignorable="d" Loaded="Page_Loaded"
Height="600">
<Grid Name="myGrid">
<GridView >
</GridView>
</Grid>
</Page>
Ad.xaml.cs:
public sealed partial class Ad : Page
{
private void Page_Loaded(object sender, RoutedEventArgs e)
{
GetGrid();
}
private async void GetGrid()
{
//Create an HTTP client object
Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();
//Add a user-agent header to the GET request.
var headers = httpClient.DefaultRequestHeaders;
//The safe way to add a header value is to use the TryParseAdd method and verify the return value is true,
//especially if the header value is coming from user input.
string header = "ie";
if (!headers.UserAgent.TryParseAdd(header))
{
throw new Exception("Invalid header value: " + header);
}
header = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)";
if (!headers.UserAgent.TryParseAdd(header))
{
throw new Exception("Invalid header value: " + header);
}
Uri requestUri = new Uri("http://localhost:7665/AdvGridView.aspx");
//Send the GET request asynchronously and retrieve the response as a string.
Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
string httpResponseBody = "";
try
{
//Send the GET request
httpResponse = await httpClient.GetAsync(requestUri);
httpResponse.EnsureSuccessStatusCode();
httpResponseBody = await httpResponse.Content.ReadAsStringAsync();
}
catch (Exception ex)
{
httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message;
}
}
}