Home > Blockchain >  unable to connect android physical device to web api in visual studio
unable to connect android physical device to web api in visual studio

Time:12-02

I have created a web api, simple dotnet framework api as below

enter image description here

Now i have create dotnet maui blazor app connecting to the android physical device like this

enter image description here

this is my button on click code in which i want to connect my application deployed on the phsical device to my web api connected on my laptop?

what is the ip address i needed to connect to from my android physical device to my web api on my laptop? it is not connecting . it is giving time-out error but first of all i needed to be sure what ip-address i needed to connect to?

  async void OnButtonClicked(object sender, EventArgs args)
{

    string baseurl = "https://10.0.2.2:44378";
    var httpClientHandler = new HttpClientHandler();
    httpClientHandler.SslProtocols = System.Security.Authentication.SslProtocols.Tls;



    httpClientHandler.ServerCertificateCustomValidationCallback =
       (message, cert, chain, errors) => { return true; };



    using (var client = new HttpClient())
    {
        client.BaseAddress = new Uri(baseurl);
        client.DefaultRequestHeaders.Clear();

        client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
        HttpResponseMessage Res = await client.GetAsync("/api/values");
        if (Res.IsSuccessStatusCode)
        {

            var EmpResponse = Res.Content.ReadAsStringAsync().Result;

        }
    }

CodePudding user response:

You first need to enable remote access to IIS Express, this link can help you on the subject: https://www.justinwalker.me/2014/07/07/access-your-iis-localhost-from-another-computer/ , then the IP you will use is the one assigned to the machine where you are running the API

CodePudding user response:

localhost of an Android device is localhost.

You need to use the IP address of the computer, on whatever network that the computer and the device share. You cannot access localhost on one machine from another machine, by definition.

And you can get the ip address by running ipconfig from dos prompt.

  • Related