title: How to send binary data in pure JavaScript?
body: <p>I want to send binary data from a html page to my server via JavaScript, but the server received not the same bytes. The received bytes seems to be converted to a unicode string, see the following example:</p>
  
  <pre><code>xhr.open('POST', '/check', true);
  xhr.setRequestHeader('cache-control', 'no-cache');
  xhr.setRequestHeader('Content-Type', 'application/octet-stream');
  xhr.send('\x41\xFE\x80');
  </code></pre>
  
  <p>The server should receive 'Aþ€' but it get <code>A├¥┬Ç</code>.</p>
  
  <p>I tested a lot of things like:</p>
  
  <pre><code>//xhr.overrideMimeType('text/plain; charset=iso-8859-1');
  //xhr.setRequestHeader('Content-type', 'text/plain; charset=iso-8859-1');
  //xhr.setRequestHeader('Content-type', 'application/xml; charset=UTF-8');
  //xhr.overrideMimeType('text/plain; charset=x-user-defined');
  //xhr.overrideMimeType('text\/plain; charset=x-user-defined');
  </code></pre>
  
  <p>On server side I run <em>plackup</em> (<em><a href="http://localhost:5000/index.html" rel="nofollow noreferrer">http://localhost:5000/index.html</a></em>), and <code>$env-&gt;{'CONTENT_LENGTH'}</code> is 5, so the server really seems to get the 5 bytes <code>A├¥┬Ç</code>.</p>
  
  <p>Any hint how to receive the original binary data would be great.</p>