I want applications to embed the REST API in the Device Portal in my applications. But I cannot connect to 127.0.0.1 with HttpClient and another API, similar to the fact that even in System.Net and Windows.Web.Http there was always an exception. "Connection to server cannot be established."
Click to see image.
But, it ONLY happens in the RS1 build (104393). In TH2 build (10568) everything works like a charm.
Here is my code:
when i use Windows.Web.Http
private async void dvInfo_Click(object sender, RoutedEventArgs e)
{
try
{
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.TryParseAdd("*/*");
string ResponseString = await httpClient.GetStringAsync(new Uri("http://127.0.0.1/api/os/machinename"));
txtStatus.Text = ResponseString.ToString();
}
catch (Exception ex)
{
var msg = new MessageDialog(ex, "Sorry, we got some error");
}
}
I am also trying to use System.Netthe same exception
private async void dvInfo_Click(object sender, RoutedEventArgs e)
{
try
{
Uri uri = new Uri("http://127.0.0.1/api/os/machinename");
var httpClient = new HttpClient();
var ResponseString = await httpClient.GetAsync(uri);
txtStatus.Text = ResponseString.ToString();
}
catch (Exception ex)
{
var msg = new MessageDialog(ex, "Sorry, we got some error");
}
}
Help: 3