rest-client get header only

K

Keith Langdon

Hi, using the great rest-client from Adam Wiggins, 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.
 
M

Michael Guterl

Hi Keith,

Hi, using the great rest-client from Adam Wiggins, 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 Guterl
 
M

Mark Thomas

Hi, using the great rest-client from Adam Wiggins, 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.
 
K

Keith Langdon

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top