I have this code:
var content = new ByteArrayContent(Encoding.ASCII.GetBytes(String.Concat("GET\t", _licencia, "\n")));
var recibido = await _client.PostAsync(fullUri, content);
var response = recibido.StatusCode;
this.IsOnline = response == HttpStatusCode.OK;
string contenido = await recibido.Content.ReadAsStringAsync();
if (this.IsOnline)
{
string data = contenido.TrimEnd();
List<string> transacciones = String.IsNullOrEmpty(data) ? null : data.Split('\n').ToList();
var guardadas = ProcessTransactions(transacciones);
if (guardadas != null)
{
StringBuilder sb = new StringBuilder(String.Concat("OK\t", _licencia, "\n"));
content = new ByteArrayContent(Encoding.ASCII.GetBytes(sb.ToString()));
recibido = await _client.PostAsync(fullUri, content);
Please see the first PostAsync call:
var content = new ByteArrayContent(Encoding.ASCII.GetBytes(String.Concat("GET\t", _licencia, "\n")));
var recibido = await _client.PostAsync(fullUri, content);
In this case, content length is only 34 bytes. So far, so good. Server receives the requirement correctly. But now see the second PostAsync call:
StringBuilder sb = new StringBuilder(String.Concat("OK\t", _licencia, "\n"));
content = new ByteArrayContent(Encoding.ASCII.GetBytes(sb.ToString()));
recibido = await _client.PostAsync(fullUri, content);
In this case, content length is 33 bytes. However, that call gets blocked and finally it throws Task Cancelled Exception. This is because of the timeout, which is defined by the HttpClient to be 1 minute 40 seconds.
Why the second call gets blocked? How can I solve it?
Thanks Jaime