title: Wrong encoding on PowerShell Invoke-WebRequest POST
body: <p>I'm using Invoke-WebRequest POST method to send an text data. After sending the text in a wrong encoding.</p>
  
  <p>Script:</p>
  
  <pre><code>$postData = "žluťoučký kůň úpěl ďábelské ódy"
  Invoke-WebRequest -Uri 'http://www.mydomain.com/' -Method Post -Body $postData -ContentType "text/plain; charset=utf-8"
  </code></pre>
  
  <p>Fiddler:</p>
  
  <pre><code>POST http://www.mydomain.com/ HTTP/1.1
  User-Agent: Mozilla/5.0 (Windows NT; Windows NT 6.2; cs-CZ) WindowsPowerShell/4.0
  Content-Type: text/plain; charset=utf-8
  Host: www.mydomain.com
  Content-Length: 31
  
  zlutouck� kun �pel d�belsk� �dy
  </code></pre>
  
  <p><strong>Edited</strong>:</p>
  
  <p>It seems that it is necessary to first convert the text into utf8. PowerShell ISE uses a different encoding by default.
  In my case, windows-1250.</p>
  
  <pre><code>$text = "žluťoučký kůň úpěl ďábelské ódy"
  $postData = [System.Text.Encoding]::UTF8.GetBytes($text)
  Invoke-WebRequest -Uri 'http://www.mydomain.com/' -Method Post -Body $postData -ContentType "text/plain; charset=utf-8"
  </code></pre>