forked from augustl/net-http-cheat-sheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse.rb
21 lines (15 loc) · 772 Bytes
/
response.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require "net/http"
require "uri"
uri = URI.parse("http://google.com/")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
response.code # => 301
response.body # => The body (HTML, XML, blob, whatever)
# Headers are lowercased
response["cache-control"] # => public, max-age=2592000
# Listing all headers
response.each_header { |h| do_something(h, response[h]) } # => location = http://www.google.com/
# => content-type = text/html; charset=UTF-8
# => cache-control = public, max-age=2592000
# etc...