I'm kind of new to RESTful consumption using http client in .net and i'm having trouble understanding how to use the retry-after header when polling an external API.
This is what i have to poll currently:
HttpResponseMessage result = null;
var success = false;
var maxAttempts = 7;
var attempts = 0;
using (var client = new HttpClient())
{
do
{
var url = "https://xxxxxxxxxxxxxxx";
result = await client.GetAsync(url);
attempts++;
if(result.StatusCode == HttpStatusCode.OK || attempts == maxAttempts)
success = true;
}
while (!success);
}
return result;
As you can see, i keep polling the endpoint until i've either got an OK response or the max attempts has been reached (to stop continuous looping).
How can i use the retry-after header from the response i get to dictate how long i wait between each of the calls in the loop?
I just cant work out how to apply this to my situation.
Thanks,