rest-client get header only

Discussion in 'Ruby' started by Keith Langdon, Sep 30, 2008.

  1. 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-forum.com/.
     
    Keith Langdon, Sep 30, 2008
    #1
    1. Advertising

  2. Hi Keith,

    On Tue, Sep 30, 2008 at 7:45 AM, Keith Langdon <> 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.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
     
    Michael Guterl, Sep 30, 2008
    #2
    1. Advertising

  3. Keith Langdon

    Mark Thomas Guest

    On Sep 30, 7:45 am, Keith Langdon <> 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.
     
    Mark Thomas, Sep 30, 2008
    #3
  4. 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-forum.com/.
     
    Keith Langdon, Sep 30, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. aleko
    Replies:
    0
    Views:
    325
    aleko
    Feb 25, 2005
  2. Alan Silver
    Replies:
    2
    Views:
    11,091
    Alan Silver
    Jul 19, 2005
  3. mlt
    Replies:
    2
    Views:
    881
    Jean-Marc Bourguet
    Jan 31, 2009
  4. kramer31

    Good REST Client

    kramer31, May 13, 2010, in forum: Java
    Replies:
    0
    Views:
    361
    kramer31
    May 13, 2010
  5. Amil Hanish

    *** REST, large POST, and "Server Error" (for gurus only)

    Amil Hanish, Jul 30, 2009, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    736
    Amil Hanish
    Jul 30, 2009
Loading...

Share This Page