make a http head request in ruby

You can make a HTTP HEAD request in Ruby using the Net::HTTP module by creating a new instance of Net::HTTP and calling the head method on it. Here's an example:

main.rb
require 'uri'
require 'net/http'

uri = URI.parse('http://example.com')
http = Net::HTTP.new(uri.host, uri.port)
response = http.head(uri.path)

puts response.code
puts response['content-type']
puts response['last-modified']
225 chars
11 lines

In this example, we're making a HTTP HEAD request to http://example.com and printing out the response code, content type, and last modified headers. The Net::HTTP module automatically handles building the HTTP request and parsing the response headers.

gistlibby LogSnag