title: Cannot send the same request message multiple times using Func<HttpRequestMessage>
body: <p>Our API has retry logic for calling another endpoint. But it kept giving me an error of </p>
  
  <blockquote>
    <p>The request message was already sent. Cannot send the same request
    message multiple times</p>
  </blockquote>
  
  <p>Here's my code</p>
  
  <pre><code>public async Task&lt;object&gt; GetResponse()
  {
      var httpRequestMessage = ConstructHttpRequestForBatchUpdate(batchRequest, client, requestUri);
      HttpResponseMessage httpResponseMessage = await _retryHttpRequest.ExecuteAsync(() =&gt; httpRequestMessage, client, maxRetryValue);
  }
  
  private HttpRequestMessage ConstructHttpRequestForBatchUpdate(JArray batchRequest, HttpClient client, Uri requestUri)
  {
      var batchReqStr = JsonConvert.SerializeObject(batchRequest);
      client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
      var httpRequestMessage = new HttpRequestMessage()
      {
          Content = new StringContent(batchReqStr, Encoding.UTF8, "application/json"),
          Method = HttpMethod.Put,
          RequestUri = requestUri
      };
      return httpRequestMessage;
  }
  
  
  public class RetryHttpRequest : IRetryHttpRequest
  {
      public async Task&lt;HttpResponseMessage&gt; ExecuteAsync(Func&lt;HttpRequestMessage&gt; requestMessage, HttpClient client, int maxTryValue)
      {
          var remainingTries = maxTryValue;
          var exceptions = new List&lt;Exception&gt;();
          do
          {
              --remainingTries;
              try
              {
                  return await ExecuteSingleAsync(requestMessage(), client);
              }
              catch (Exception e)
              {
                  exceptions.Add(e);
              }
          }
          while (remainingTries &gt; 0);
          throw new AggregateException(exceptions);
      }
      public async Task&lt;HttpResponseMessage&gt; ExecuteSingleAsync(HttpRequestMessage requestMessage, HttpClient client)
      {
          try
          {
              HttpResponseMessage httpResponseMessage = await client.SendAsync(requestMessage);
              if (httpResponseMessage.IsSuccessStatusCode)
              {
                  return httpResponseMessage;
              }
              else
              {
                  var exception = new InvalidOperationException();
                  throw new Exception();
              }
          }
          catch (HttpRequestException httpException)
          {
              throw httpException;
          }
      }
  }
  </code></pre>
  
  <p>To my understanding, <code>Func&lt;HttpRequestMessage&gt;</code> allows it to create a new instance of <code>HttpRequestMessage</code>. For example, for this line of code</p>
  
  <pre><code>return await ExecuteSingleAsync(requestMessage(), client);
  </code></pre>
  
  <p><code>requestMessage()</code> is creating a new instance for every loop. But if my understanding is correct, i am not sure why it is still giving me this error of sending the same request. </p>