sidy3d
sidy3d

Reputation: 549

Handle no internet with HttpClient

I have a windows phone runtime app that uses the HttpClient to make web request. How can I handle a connection exception (no internet).

Thanks

Upvotes: 0

Views: 1771

Answers (1)

vITs
vITs

Reputation: 1560

First thing you can do before Http request:

    using Microsoft.Phone.Net.NetworkInformation;

    private void CheckInetConnection()
    {
        if (NetworkInterface.GetIsNetworkAvailable() == true)
        {
            //Internet avalaible
        }
        else
        {
        //No connection available
        }
    }

and for exception handling of HttpClient check this

response.StatusCode will give you the status of response.

Upvotes: 4

Related Questions