title: Reusing HttpRequestMessage in Polly retry policies
body: <p>An <code>HttpRequestMessage</code> object can only be used one time; future attempts to use the same object throw an exception. I'm using Polly to retry some requests and I'm hitting this issue. I know how I can clone a request, there are plenty of examples on SO, but I can't figure out how to clone a request and send that new request whenever Polly retries. How can I accomplish this?</p>
  
  <p>These are my policies, for reference. This is a Xamarin app. I want to retry a few times in case of network failures, and if the response is unauthorized I want to re-auth with saved credentials and try the original request again.</p>
  
  <pre><code>public static PolicyWrap&lt;HttpResponseMessage&gt; RetryPolicy
  {
      get =&gt; WaitAndRetryPolicy.WrapAsync(ReAuthPolicy);
  }
  
  private static IAsyncPolicy WaitAndRetryPolicy
  {
      get =&gt; Policy.Handle&lt;WebException&gt;().WaitAndRetryAsync(4, _ =&gt; TimeSpan.FromSeconds(2));
  }
  
  private static IAsyncPolicy&lt;HttpResponseMessage&gt; ReAuthPolicy
  {
      get =&gt; Policy.HandleResult&lt;HttpResponseMessage&gt;(x =&gt; x.StatusCode == HttpStatusCode.Unauthorized)
          .RetryAsync((_, __) =&gt; CoreService.LogInWithSavedCredsAsync(true));
  }
  </code></pre>
  
  <p>This doesn't work because of the <code>HttpRequestMessage</code> reuse, but it's what I'm trying to accomplish:</p>
  
  <pre><code>var request = new HttpRequestMessage(HttpMethod.Post, "some_endpoint")
  {
      Content = new StringContent("some content")
  };
  
  request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
  
  var policyResponse = await ConnectivityHelper.RetryPolicy
      .ExecuteAndCaptureAsync(() =&gt; _client.SendAsync(request)).ConfigureAwait(false);
  
  // handle outcome
  </code></pre>