Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Error when connecting to Web API

$
0
0

I am attempting to connect to a Web API project and having problems. I am using one of the basic controllers installed with the API project, and when I use the URL directly in a browser, it works: localhost:11443/api/Values

However, when trying to debug by connecting through a service class in a Xamarin project, I get the exception "An unhandled exception occured.", complete with the incorrect spelling. I am using the ModernHttpClient library. I had tried the System.Net.Http library first, but I had no better results using that. Here is the simplified method:

    public async Task<bool> RegisterAsync(string email, string password, string confirmPassword) {

        var model = new RegisterBindingModel() {
            Email = email,
            Password = password,
            ConfirmPassword = confirmPassword
        };

        using (var client = new HttpClient(new NativeMessageHandler())) {
            **var response = await client.GetAsync("localhost:11443/api/Values");**
            if (response.IsSuccessStatusCode) {
                var data = await response.Content.ReadAsStreamAsync();
            }
        }

        return true;
    }

I am using an emulator. The bolded line is the one that fails and generates the exception. What am I doing wrong?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>