HttpClient GetAsync throws "Task was cancelled" exception

DuraiHDuraiH USMember ✭✭

It was working earlier but all of a sudden it throws Task was cancelled I would like to know why it happens suddenly and how we can rectify it ?

public static async Task<bool> HasConnectivity()
        {
            Uri authUri = new Uri("https://google.com/");
            HttpClient client = new HttpClient();

            try
            {

                HttpResponseMessage resp = await client.GetAsync(authUri);
                string content = await resp.Content.ReadAsStringAsync();

                if (resp.IsSuccessStatusCode)
                {
                    return true;
                }

                return false;
            }
            catch (Exception e)
            {
                Debug.WriteLine("Network connection error: " + e.Message);
                return false;
            }
        }

Here is the screenshot of exception

Best Answers

  • DuraiHDuraiH US ✭✭
    Accepted Answer

    finally found out that there is a problem with the wifi it has got some ssl problem

Answers

  • DuraiHDuraiH USMember ✭✭

    yeah I tried in browser it works... I am just trying to reach https://google.com/

  • DuraiHDuraiH USMember ✭✭

    Its crazy it started working from today morning without any problem ... I am still wondering what caused this problem ...

    I don't understand what would have caused it

  • DuraiHDuraiH USMember ✭✭
    Accepted Answer

    finally found out that there is a problem with the wifi it has got some ssl problem

Sign In or Register to comment.