Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

PostAsync has occurred “the request timed out” on iOS Xamarin Forms

$
0
0

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


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>