header image


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.

  1. require ‘open-uri’
  2.  
  3. 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!

Similar Posts:cheap tramadol



If you liked the article, subscribe to the feed   and follow me on twitter!.


      

2 Responses to “”

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

    , [...] [Ruby] 透過 http-basic-auth 下載檔案 分類於 Uncategorized — magicsword @ 3:39 午後 From: https://rubyrailways.com/downloading-a-file-behind-http-basic-auth/sourcecode language=’css’]#!/usr/bin/env ruby [...]

  2. Pascal Van Hecke Says:

    , 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 :-)

Leave a Reply




Bad Behavior has blocked 2412 access attempts in the last 7 days.