I use xamarin forms to create an mobile app for Android and iOS. I need to make Http Request, so I use HttpClient.
Here is a simple code of request :
var client = new HttpClient(); try { string requestUrl = URL_DATABASE + "xxx"; var content = new StringContent("{\"param\":\"" + param+ "\"}", Encoding.UTF8, "application/json"); var response = await client.PostAsync(requestUrl, content); if (response.StatusCode == HttpStatusCode.OK) { var result = await response.Content.ReadAsStringAsync(); return result; } return "{\"status\":-1}"; } catch (Exception ex) // Error catched : "the request timed out" { return "{\"status\":-1}"; }
I used Postman to check result of my request and work's well, I got good response without timeout.
I noticed that error occurs sometimes but can last an hour.
Thank you in advance for your help