Downloading a File Behind http-basic-auth

There is a great number of possibilities to do this in Ruby (just to mention a few: standard net/http, curb, mechanize, rio etc.). I have chosen a semi-standard way (=no need to learn new syntax, but definitely simpler than net/http): open-uri.

require 'open-uri'

open('target.file','w') {|f| f.write open("my.url.com/source.file", :http_basic_authentication=>['ueser', 'pass']) }

I am using Ruby for more than 2 years already but it’s succinctness still keeps me amazed!

2 thoughts on “Downloading a File Behind http-basic-auth

  1. Pingback: [Ruby] 透過 http-basic-auth 下載檔案 « Reading for Life

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>