[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

rest-client get header only

Keith Langdon

9/30/2008 11:45:00 AM

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.
--
Posted via http://www.ruby-....

3 Answers

Michael Guterl

9/30/2008 1:28:00 PM

0

Hi Keith,

On Tue, Sep 30, 2008 at 7:45 AM, Keith Langdon <keith@masite.co.uk> wrote:
> 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... it
does not appear that there is a RestClient#head method. However,
looking at the internals you may be able to do:

uri = 'http://googl...
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

Mark Thomas

9/30/2008 2:42:00 PM

0

On Sep 30, 7:45 am, Keith Langdon <ke...@masite.co.uk> wrote:
> 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.

Keith Langdon

9/30/2008 4:02:00 PM

0

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.

--
Posted via http://www.ruby-....