In a Xamarin.Forms application I try to connect to the Exosites api (which is not part of the project so I can't change that one so SignalR or so).
It all works fine for "normal" requests.
The api also supports long polling requests - in the manual it says that the client has to set the header "Request-Timeout" to the request.
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
request.Headers.Add("Request-Timeout", "10000");
var response = await client.SendAsync(request);
But doing so, I don't get any answer back, even if i set the timeout to a very small value like 1 (ms). If I set a timeout on a request to another endpoint on Exosites which does not check on it it works fine. Sending the exact same request without the "Request-Timeout" header also works fine.
Does anyone have experience with long polling calls in Xamarin using HttpClient?
Thanks a lot!
tschuege
Actually, it's a lot easier than that.
using (var client = new HttpClient())
{
client.Timeout = TimeSpan.FromSeconds(_timeoutSeconds);
}
PS: Be sure to always wrap your new HttpClient() in a using block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With