title: HttpClient.PostAsync HttpContent parameter value null after POSTing data
body: <p>I have a loop that is iterating through a short list of <code>URIs</code> and needs to send each of them the <em><strong>same</strong></em> content. That <code>HttpContent</code> resides in a variable passed into the call to <code>PostAsync</code>. The problem I'm incurring is that the <em>1st</em> call works perfectly, but all subsequent calls fail because the request content is <code>null</code> after the 1st call completes.</p>
  
  <p>I would assume my understanding of the <code>PostAsync</code> call under the covers might be lacking some low level detail on the object and it's lifetime (or lack there of) so hopefully someone can shed some light on it for me.</p>
  
  <p>The code looks as follows:</p>
  
  <pre><code>HttpResponseMessage httpResponseMessage = httpClient.PostAsync(destionationUri, messageContent).Result;
  </code></pre>
  
  <p>The variable in question is <code>messageContent</code> which is of type <code>MultipartFormDataContent</code> which derives from <code>HttpContent</code>. I suppose some brute method of copying the value to a new and separate location for reuse might work, but I'm looking to understand why this happening and a proper method for allowing the content to persist during the loop.</p>
  
  <p>Does anyone know how I can fix this issue, and upon looping around the code above, the <code>messageContent</code> value will persist between iterations? </p>
  
  <p><strong>EDIT:</strong> I went ahead and refactored the code to <em>rebuild</em> the <code>MultipartFormDataContent</code> from scratch using the same data prior to each call to <code>PostAsync</code> using a <em>new</em> instance of <code>HttpClient</code>. The call to rebuild the <code>HtppContent</code> actually worked; the value is not null. However when I now go to make a subsequent call to <code>PostAsync</code> and access <code>.Result</code> I get the following error:</p>
  
  <blockquote>
    <p>Error while copying content to a stream. Cannot access a closed
    Stream.</p>
  </blockquote>
  
  <p><strong>EDIT 2:</strong> Upon inspecting the <em>2nd</em> call to my method to rebuild the <code>MultipartFormDataContent</code> object from scratch, I notice that my attachment property when inspecting it's <code>ContentStream</code> property (of a <code>Mail.MailMessage</code> object) states the following:</p>
  
  <blockquote>
    <p>attachment.ContentStream.Position threw an exception of type
    <code>System.ObjectDisposedException</code></p>
  </blockquote>
  
  <p>All of the properties indicate the <code>ContentStream</code> can no longer be read because it's disposed. The call to <code>PostAsync().Result</code> apparently is disposing of the stream and is potentially the root issue. However I'm still unable to find a workable solution.</p>