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