Rest-client get header only

Hi, using the great rest-client from Adam W., but I can’t seam to
be able work out how to get just the HEAD of a URL.
i.e. in curl I would : curl -I URL

I’m getting the data just fine with:
return_data = RestClient.get “URL”

Is there a way of doing this, or should I go about it a different way?

I’m using it to get the filename sent back from a send_data command in a
rails app.

Still very new to all this ruby/rails jive, but liking it so far!

Keith.

Hi Keith,

On Tue, Sep 30, 2008 at 7:45 AM, Keith L. [email protected]
wrote:

Hi, using the great rest-client from Adam W., but I can’t seam to
be able work out how to get just the HEAD of a URL.
i.e. in curl I would : curl -I URL

I’m getting the data just fine with:
return_data = RestClient.get “URL”

Is there a way of doing this, or should I go about it a different way?

Looking at the documentation at http://rest-client.heroku.com/rdoc/ it
does not appear that there is a RestClient#head method. However,
looking at the internals you may be able to do:

uri = ‘http://google.com
headers = {}

RestClient::Request.execute(:method => :head,
:url => url,
:headers => headers)

I’m using it to get the filename sent back from a send_data command in a
rails app.

Still very new to all this ruby/rails jive, but liking it so far!

Welcome aboard!

Michael G.

On Sep 30, 7:45 am, Keith L. [email protected] wrote:

Hi, using the great rest-client from Adam W., but I can’t seam to
be able work out how to get just the HEAD of a URL.
i.e. in curl I would : curl -I URL

I’m getting the data just fine with:
return_data = RestClient.get “URL”

Is there a way of doing this, or should I go about it a different way?

The ruby standard library has net/http, with which you can do:

require ‘net/http’

conn = Net::HTTP.start(‘www.whatever.com’)
conn.head(‘/’).each_header do |k,v|
puts “#{k} = #{v}”
end

– Mark.

Thanks Michael, tried to use the :method => :head, but couldn’t get it
to fly.
Sure there is a way of using that method if you know your way round ruby
better than I. Cheers for the suggestion.

The ruby standard library has net/http, with which you can do:

require ‘net/http’

conn = Net::HTTP.start(‘www.whatever.com’)
conn.head(‘/’).each_header do |k,v|
puts “#{k} = #{v}”
end

Thanks Mark that cracked it!

Now able to get the filename, and the actual data, so I can save to
disk, rather than using a default name for the data as I was before.

Many thanks,

Keith.