Forum Cross Platform with Xamarin
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Extremely Slow POST-Requests with Xamarin

Hello. I now used 3 different classes but the result is the same: whether i do HTTPS or HTTP request, the time for sending the web request is 10-20 seconds. this can NOT be!
what i've done:

  • checking my server - 0.2s answer time
  • setting proxy server to 0
  • raising default maximum connections
  • try 3 different classes
  • did everything async
  • Expect100Continue = false
  • use using blocks around the streams

i came to the conclusion that this can be just a Xamarin Error. i tested with android and i have no other devices to test on. plus emulators won't work because they won't even start up.
so maybe someone can help me here because i have posted in 3... no 4 forums now and nobody can help me.


  • PerHungebergMllerPerHungebergMller DKMember ✭✭✭

    @Kokujou Are you getting the 0.2s response time when you do a POST request in a simple .NET console app with HttpClient ?

    Have a look at native HttpClient implementations:

    Also check this out:

  • KokujouKokujou DEMember ✭✭

    i did everything mentioned in that topic. i didn't tried another .net console app but i used some online tools like both on my android and my PC. plus i measured the time my code takes on the server to connect to my database - 0.2s
    implementations i tried:
    RestSharp, System.Net.Http, HttpWebRequest, ModernHttpClient, everything with the same result.

  • KokujouKokujou DEMember ✭✭
    edited December 2017

    ah sorry i didn't get you right. i had to set this setting in android to:
    Implementation: AndroidClientHandler
    SSL/TLS: Native TLS 1.2+
    if i set the HTTP implementation to the other default value i get a lot of "need to respecify runtime" messages because the target framework is 7.0 and they want 7.1.
    well the phone i'm testing on is on 7.0 so what can i do? is it worth trying?

  • KokujouKokujou DEMember ✭✭

    And the answer was, and i really hope everybody with the same problem reads this:
    Setting the Protocol Version to HTTP 1.1!
    with doing so it speeded up to below 1s for the whole code.

  • MrDaneeyulMrDaneeyul Member ✭✭
    edited September 2018

    @Kokujou said:
    And the answer was, and i really hope everybody with the same problem reads this:
    Setting the Protocol Version to HTTP 1.1!
    with doing so it speeded up to below 1s for the whole code.

    I'm having a slow POST issue as well. How did you set the ProtocolVersion? I'm using HttpClient.PostAsync(), but the only option I could find to change ProtocolVersion was in HttpResponseMessage. Are you passing the response in somewhere else? Does modifying the response.ProtocolVersion change anything in a PostAsync() when it's the returned object, not any of the arguments?

  • KokujouKokujou DEMember ✭✭

    it's been a really long time so i'm not perfectly sure and the project is already finished so i can#t find it here anymore...
    but i think it was somewhere in the project settings, the android project settings.
    as far as i recalls this is not a xamarin mistake but an android mistake, so somewhere in the android project settings you can settup to HTTP 1.1
    sadly i can't look it up myself since i have problems with visual studio right now XD i hope you can find it, if not i'll look it up again for you! :)

  • MrDaneeyulMrDaneeyul Member ✭✭

    That's alright, thanks for checking! :smile: So I found TLS 1.1 settings in the Android Project Settings, but didn't want to change that, as Google Play is (I believe) going to be enforcing TLS 1.2 here soon. I'm not sure that's what you were referring to anyway. I couldn't find anything else in the project settings. There's an old way of setting up a post using HttpWebRequest instead of HttpClient where you set the ProtocolVersion to be 1.1. I was pretty close to getting that to work, I think, but we ended up heading a different direction for the time being.

  • KokujouKokujou DEMember ✭✭

    i found the project and those are my settings...
    but somehow they look different...
    maybe something has been updated. but i have some other things to try out for you.
    this is the only related code i could find in my project:
    ServicePointManager.ServerCertificateValidationCallback += (a, b, c, d) => { return true; };
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    ServicePointManager.Expect100Continue = false;
    ServicePointManager.DefaultConnectionLimit = 100;
    i'm sorry i should've been more precise with my solution but since i didn#t provide code i'm pretty sure it has been some setting...
    but i can't find it anymore too, which makes me thing there has been some bigger update...
    i think it may be the setting HTTP Client in the advanced window.
    i wish i could be of more help.

    in case this still doesn't help: what i do remember is that its a problem of android, not xamarin. so look it up in google like "android slow post requests" or something... i remember tracking this error back to some android error functions and googling them.

Sign In or Register to comment.