'GetStringAsync from HttpClient doesn't return anything C#

We are trying to get information from an API. We use the following code to get an answer. It's a Xamarin Project. We are running it on an Android Emulator with internet connection. Android-Version:11.
When it gets to the line:

var result = await client.GetStringAsync(endpoint);

It just stops and doesn't throw an error. Why is this happening?

private async void Button_Clicked(object sender, EventArgs e)
    {
        var Get = await AsyncGet();
        //await GetItemsAsync();
    }

    public static async Task<string> AsyncGet()
    {
        HttpClientHandler GetInsecureHandler()
        {
            HttpClientHandler handler = new HttpClientHandler();
            handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) =>
            {
                if (cert.Issuer.Equals("CN=localhost"))
                    return true;
                return errors == System.Net.Security.SslPolicyErrors.None;
            };
            return handler;
        }
        var client = new HttpClient(GetInsecureHandler());
        try
        {
            var endpoint = new Uri("My Uri");
            var result = await client.GetStringAsync(endpoint);
            var json = JsonConvert.DeserializeObject<string>(result);
            return result;
        }
        catch (Exception ex)
        {
            string checkResult = "Error " + ex.ToString();
            client.Dispose();
            return checkResult;
        }


    }

Alternative code:

async Task<string> GetItemsAsync()
    {
        using (HttpClient client = new HttpClient())
        {
            var response = await client.GetAsync("My Uri");
            return await response.Content.ReadAsStringAsync();
        }


    }

This Code does return the information but only in the console. When it is run with Xamarin, it also doesn't return anything.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source