title: Post XML file via Ruby
body: <p>i got the following form on an external service (someurl.com/xmlimport.html) which is protected by basic auth.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;title&gt;Upload&lt;/title&gt;&lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Upload&lt;/h1&gt;
  &lt;h2&gt;XML Upload&lt;/h2&gt;
  &lt;!--&lt;form action="/cgi-bin/xmlimport.pl" method="post" accept-charset="UTF-8" enctype="multipart/form-data"&gt;--&gt;
  &lt;form action="/cgi-bin/xmlimport.pl" method="post" enctype="multipart/form-data"&gt;
  Datei: &lt;input name="dateiname" type="file" size="100" accept="text/*"&gt;
  &lt;input type="submit" value="Absenden"/&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>I want to post xml files via ruby. This is what i got so far:</p>
  
  <pre><code>require "net/http"
  require "uri"
  
  uri = URI.parse('http://someurl.com/xmlimport.html')
  file = "upload.xml"
  
  
  post_body = []
  post_body &lt;&lt; "Content-Disposition: form-data; name='datafile'; filename='#{File.basename(file)}'rn"
  post_body &lt;&lt; "Content-Type: text/plainrn"
  post_body &lt;&lt; "rn"
  post_body &lt;&lt; File.read(file)
  
  
  puts post_body
  
  http = Net::HTTP.new(uri.host, uri.port)
  request = Net::HTTP::Post.new(uri.request_uri)
  request.basic_auth "user", "pass"
  request.body = post_body.join
  request["Content-Type"] = "multipart/form-data"
  
  resp = http.request(request)
  
  puts resp.body
  </code></pre>
  
  <p>The response is the content of my xml file and the form. But nothing is processed. What am I doing wrong?</p>
  
  <p>Thanks in advance.</p>