Downloading a File Behind http-basic-auth
April 7th, 2008
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!
tags:
April 7th, 2008 at 8:41 am
[…] [Ruby] 透過 http-basic-auth 下載檔案 分類於 Uncategorized — magicsword @ 3:39 午後 From: http://www.rubyrailways.com/downloading-a-file-behind-http-basic-auth/[sourcecode language=’css’]#!/usr/bin/env ruby […]
April 25th, 2008 at 10:16 am
I wrote something similar for republishing feeds behind http basic authentication just a few months ago:
http://php.vanhecke.info/2008/01/20/republish-a-feed-or-other-data-protected-by-http-basic-authentication/
(using the PHP snoopy class).
Indeed a lot more verbose than ruby