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

  • Question

  • User391138 posted

    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

    Friday, July 3, 2020 9:25 AM

All replies

  • User369979 posted

    Is this request a http one? If so, you need to disable the ATS in iOS: https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/ats Put this


    into your info.plist and then have a test again.

    Monday, July 6, 2020 8:49 AM
  • User391138 posted

    Thank you @LandLu for your reply but I already put this key to true

    Monday, July 6, 2020 2:34 PM
  • User369979 posted

    Have you tried other requests? i.e. Test the apis listed by searching. Maybe like this one: http://dummy.restapiexample.com/api/v1/employees

    Wednesday, July 8, 2020 9:11 AM