JDiek JDiek - 3 months ago 6
JSON Question

On some machines my app fails reading a JSON feed from a web Address

I have a UWP app using C#. I use HttpClient to retrieve a JSON file from the server. On some machines however it fails with a "unable to connect to the remote server". The server is accessible through the browser though. Any ideas?


The HttpClient has a Timeout property. Set that to the timeout you want and handle the TimeoutException to do specific things on the timeout.

HttpClient client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(5);
HttpResponseMessage response = null;
    response = await client.GetAsync(url);
catch (TimeoutException)
    // handle the timeout, e.g. return false
    return false;
catch (Exception ex)
    // handle the other errors, e.g. throw it
    throw (ex);