Method: Simple2ch.fetch

Defined in:
lib/simple2ch.rb

.fetch(url) ⇒ String

HTTPでGETする

Parameters:

  • url (URI)

    URL

Returns:

  • (String)

    取得本文



23
24
25
26
27
28
29
# File 'lib/simple2ch.rb', line 23

def self.fetch(url)
  req = Net::HTTP::Get.new(url.path)
  res = Net::HTTP.start(url.host, url.port) {|http|
    http.request(req)
  }
  res.body.force_encoding("cp932").encode!('utf-8', :undef => :replace)
end