I'm sending data to a databricks api with a bad bearer token to test a Polly retry policy, but I get this exception:
InvalidOperation exception: The request message was already sent. Cannot send the same request message multiple times.
HttpResponseMessage response = null;
response = await Policy
.HandleResult<HttpResponseMessage>(message => !message.IsSuccessStatusCode)
.WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(2), (result, timeSpan, retryCount, context) =>
{
Console.WriteLine($"Request failed with {result.Result.StatusCode}. Waiting {timeSpan} before next retry. Retry attempt {retryCount}");
})
.ExecuteAsync(() => httpClient.SendAsync(request));
/***********************************
* End retry from
* https://www.jerriepelser.com/blog/retry-network-requests-with-polly/
* ********************************/
// HttpResponseMessage response = await httpClient.SendAsync(request);
// response = await httpClient.SendAsync(request);
resultContent = await response.Content.ReadAsStringAsync();
response.EnsureSuccessStatusCode();