Unable to connect to the 127.0.0.1 (localhost) device portal in UWP using HttpClient or otherwise (Windows 10 Mobile RS1 only)

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")); //got exception here, ResponseString null
                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); //got exception here, ResponseString null
                txtStatus.Text = ResponseString.ToString();
            }
            catch (Exception ex)
            {
                var msg = new MessageDialog(ex, "Sorry, we got some error"); //...
            }
        }

Help: 3

+4
2

[] Windows.Web.Http, https uri http, , cert/ignore, :

var filter = new HttpBaseProtocolFilter();
filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Expired);
filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted);
filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName);
var http = new HttpClient(filter);
+1

, Mobile. , , .

? , IP- . . loopback protection, API . , loopback VS, .

+2

Source: https://habr.com/ru/post/1649983/


All Articles