0

I am using a post function in my code but sometimes it gives a timeout, long duration is not the problem but I need the code to wait on the response. Using this code:

using (var client = new HttpClient())
            using (var formData = new MultipartFormDataContent())
            {
                formData.Add(Hdata, "data", "data");
                formData.Add(Hclient, "client", "client");
                formData.Add(Hpage, "page", "page");
                formData.Add(Hloop, "loop", "loop");
                formData.Add(Hproperties, "properties", "properties");
                formData.Add(Hrelation, "user", "user");
                formData.Add(Hbinary, "binary", "binary");
                requestMessage.Content = formData;

                //client.Timeout = TimeSpan.FromSeconds(300);;
                var response = client.SendAsync(requestMessage, HttpCompletionOption.ResponseContentRead);

                using (StreamReader sr = new StreamReader(response.Result.Content.ReadAsStreamAsync().Result))
                {
                    if (sr != null)
                    {
                        json = sr.ReadToEnd();
                    }
                }
            }

Tried in the past many things but non of them worked, can somebody advise me what to do?

UPDATE: forgot this is an Xamarin Visual Studio project

Darshan Dave
  • 645
  • 2
  • 9
  • 32
user3763117
  • 327
  • 1
  • 5
  • 18

1 Answers1

0

You can set this value in web.config. For example, to change the timeout for one specific page:

<location path="somefile.aspx">
<system.web>
    <httpRuntime executionTimeout="180"/>
</system.web>

See http://msdn2.microsoft.com/en-us/library/e1f13641.aspx for more details. or You can check this answer How to change the timeout on a .NET WebClient object

Hope that helps.

Community
  • 1
  • 1
Darshan Dave
  • 645
  • 2
  • 9
  • 32