The curl man page states: If you start the data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin. The contents of the file must already be url-encoded. Multiple files can also be specified. Posting data from a file named 'foobar' would thus be done with --data @foobar".
On 9/11/07, Matt Mitchell <[EMAIL PROTECTED]> wrote: > > Hi, I just posted this to the ruby/google group. It probably belongs > here! Also, anyone know exactly what the @ symbol in the curl command > is doing? > Thanks, > Matt > > > I've got a script that uses curl, and would like (for educational > purposes mind you) to use ruby instead. This is the curl command that > works: > > F="./my_data.xml" > curl 'http://localhost:8080/update' --data-binary @$F -H 'Content- > type:text/xml; charset=utf-8' > > I've been messing with Net::Http using something like below, with > variations (Base64.encode64) but nothing works yet. Anyone know the > ruby equivlent to the curl version above? > > Thanks! > > # NOT WORKING: > my_url = 'http://localhost:8080/update' > data = File.read('my_data.xml') > url = URI.parse(my_url) > post = Net::HTTP::Post.new(url.path) > post.body = data > post.content_type = 'application/x-www-form-urlencoded; charset=utf-8' > response = Net::HTTP.start(url.host, url.port) do |http| > http.request(post) > end > puts response.body -- Michael Kimsal http://webdevradio.com