title: Content Length and Invoke-WebRequest
body: <p>I'm trying to upload an XML file using Invoke-WebRequest (Invoke-RestMethod isn't recommended for that?) but when trying to set the content-length in the header, I get the error: </p>
  
  <pre><code>Invoke-WebRequest : You must write ContentLength bytes to the request stream before calling [Begin]GetResponse.
  </code></pre>
  
  <p>Do I need to create a request stream? I've checked <a href="https://social.technet.microsoft.com/Forums/windowsserver/en-US/d18f4ae9-4a5d-495f-aa2d-fbda3d616967/invokewebrequest-you-must-write-contentlength-bytes-to-the-request-stream-before-calling" rel="nofollow noreferrer">https://social.technet.microsoft.com/Forums/windowsserver/en-US/d18f4ae9-4a5d-495f-aa2d-fbda3d616967/invokewebrequest-you-must-write-contentlength-bytes-to-the-request-stream-before-calling</a> but that doesn't seem to answer that.</p>
  
  <pre><code>$requestHeaders = @{
      "content-length" = 2182
      "Content-Type" = "application/xml"
      "Authorization"  = "Bearer " + $response.access_token
  }
  
  $body = @"
      $xml
  "@
  
  $result = Invoke-WebRequest -Method Post -Uri "{uri}" -Headers $requestHeaders -Body $Body
  </code></pre>