Forum Xamarin Xamarin.Forms

HttpClient/API calls really slow.......( Only on iOS ) Andoird and UWP are good

XamtasticXamtastic Member ✭✭✭

On Android and UWP, everything is good.

However ONLY for iOS the code just runs/executes really slow. Any ideas?

var uri = new Uri(url);

using (var client = new HttpClient())
{
    var request = (HttpWebRequest)WebRequest.Create(uri);
    request.ContentType = "application/json";
    request.Method = "POST";
    request.ServerCertificateValidationCallback += (s, cert, chain, err) => true;
    request.Headers.Add("Authorization", "Bearer " + accessToken);

    using (var streamWriter = new StreamWriter(request.GetRequestStream()))
    {
        streamWriter.Write(json);
        streamWriter.Flush();
        streamWriter.Close();
    }

    // Connect with Server
    var response = (HttpWebResponse)request.GetResponse();

    // Response
    switch (response.StatusCode)
    {
        case HttpStatusCode.Accepted:
        case HttpStatusCode.OK:
            using (var streamReader = new StreamReader(response.GetResponseStream()))
            {
                var read = streamReader.ReadToEnd();
            }
            break;
    }
}
Tagged:

Best Answer

  • XamtasticXamtastic Member ✭✭✭
    Accepted Answer

    I changed the calls from:
    Task.WaitAll(tasks.ToArray());

    To this:
    foreach (var t in tasks) { t.Wait(); }

    Only iOS gave me trouble (sluggish activity). Android and UWP were solid.

Answers

Sign In or Register to comment.