2006-03-01から1日間の記事一覧

Rubyのnet/httpでファイルをダウンロードする時に確実に例外を捕捉するには

いつも解決法を忘れて、同じ失敗をするので、備忘録を兼ねてメモ。次のように書く。 require 'net/http' Net::HTTP.version_1_2 begin Net::HTTP.start('www.example.com', 80) {|http| response = http.get('/index.html') puts response.body } rescue Exc…