title: post xml as a binary file using javascript
body: <p>I'm trying to write something that can post xml, as a binary file to an external URL (which I have no control over) in JavaScript.
  I have YUI3 available to me. And probably jQuery if I needed it.</p>
  
  <p>Any ideas? Everything I've looked at seems to be about receiving xml, rather than posting it.</p>
  
  <p><strong>Edit</strong>: The external url is an advertising bot, the xml essentially describes what sort of ad I want to get back.</p>
  
  <p>I'm forced to post as binary. I've tested using-</p>
  
  <pre><code>&lt;form enctype="multipart/form-data" action="http://something.com" method="post"&gt;
  &lt;input name="anything" type="file"&gt;something&lt;/file&gt;
  &lt;input type="submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and that works. I just need to implement in js.
  <strong>Edit #2</strong></p>
  
  <p>My solution (couldn't get it formatted properly)-</p>
  
  <p><code>var AdManager = {
      getRandomBoundary : function(){
          var today = new Date;
          return '---' + today.getTime();
      },
      fetch : function(){
          var boundary = this.getRandomBoundary();
          var xhr = new XMLHttpRequest;
          var CRLF  = "\r\n";</code></p>
  
  <pre><code>    xhr.open('POST', 'http://url.com', true);
      xhr.onreadystatechange = function(){
          if (xhr.readyState === 4)
          {
              //Parse xml(badly)
              var splitter = xhr.responseText.split('&lt;responsecontent&gt;');
              var allAds = '';
              for (var i= 1; i&lt; splitter.length; i++)
              {
                  var tempAd = splitter[i].split('&lt;/responsecontent&gt;');
                  allAds += tempAd[0];
              }
              //Html is returned encoded, so decode.
              jQuery('#results').html(jQuery("&lt;div/&gt;").html(allAds).text());
          }
      };
  
      xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);
  
      var mimeReq = "--" + boundary + CRLF;
      mimeReq += 'Content-Disposition: form-data; name="arbitrary"; filename="arbitrary.xml"' + CRLF;
      mimeReq += 'Content-Type: application/octet-stream' + CRLF + CRLF;
      mimeReq += '&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;&lt;adrequestpacket responsemarkup=\"wml\" test=\"0\" xmlns=...'+ CRLF;
      mimeReq += "--" + boundary + "--" + CRLF;
  
      xhr.send(mimeReq);
  }
  </code></pre>
  
  <p>};
  `</p>