I have below exception when i want to connect to my api. This exception is happening in some special cases. for example, when I am in my gym, i am able to reproduce it. my gym is having a wireless connection using this service https://www.freefii.de/
when I connect to it, general internet connection is fine and fast but somehow my app is returning this exception every time i make api request.
Any idea what could be the problem?
"type": "System.Net.WebException",
"message": "Error: ConnectFailure (Network subsystem is down)",
"stackTrace": " at System.Net.WebConnection.Connect (System.Net.WebOperation operation, System.Threading.CancellationToken cancellationToken) [0x00217] in :0 \n at System.Net.WebConnection.InitConnection (System.Net.WebOperation operation, System.Threading.CancellationToken cancellationToken) [0x000cc] in :0 \n at System.Net.WebOperation.Run () [0x0009a] in :0 \n at System.Net.WebCompletionSource1[T].WaitForCompletion () [0x00094] in <a13a876c512b4bd799407c195d4b8176>:0 \n at System.Net.HttpWebRequest.RunWithTimeoutWorker[T] (System.Threading.Tasks.Task
1[TResult] workerTask, System.Int32 timeout, System.Action abort, System.Func`1[TResult] aborted, System.Threading.CancellationTokenSource cts) [0x000f8] in :0 \n at System.Net.Http.HttpClientHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x002e7] in :0 ",
here is the code I am using;
private static HttpClient getClient()
{
HttpClientHandler handler = new HttpClientHandler
{
Proxy = Xamarin.Forms.DependencyService.Get<Helpers.IProxyInfoProvider>().GetProxySettings()
};
HttpClient _client= new HttpClient(handler);
return _client;
}
using (HttpClient client = getClient())
{
HttpResponseMessage response = await client.GetAsync(uri, ct)
}
In Android Project
public class ProxyInfoProvider : IProxyInfoProvider
{
public WebProxy GetProxySettings()
{
string proxyHost = JavaSystem.GetProperty("http.proxyHost");
string proxyPort = JavaSystem.GetProperty("http.proxyPort");
return !string.IsNullOrEmpty(proxyHost) && !string.IsNullOrEmpty(proxyPort)
? new WebProxy($"{proxyHost}:{proxyPort}")
: null;
}
}