Search code examples
c#xamarin.formsdotnet-httpclient

Xamarin Forms HttpClient decide between two servers which one of them is up/active/responding


The scenario is this. On the company network, API URL is different and when accessed from the outside, it is different. So when the xamarin forms application starts, I need to test which of the two servers is responding to check whether it is the local network or the app is connected externally. This will be the deciding factor for which server to use for all other requests. Please note that the server is PHP based


Solution

  • You could use James Montemagno's Connectivity plugin for this. You can check whether the device you are using is online and also use the IsRemoteReachable call to see if a server can be reached.

    Also, ensure that all the proper rights required by the plugin are selected in the Android Manifest.