Topic: How to do https POST

Can some one help me to do HTTPS and using Net::HTTP.post_form or some other method?
I'm trying to POST to REST like endpoint URL...
Thanks a lot in advance. Whoever helps me get a nice lunch or dinner treat

Re: How to do https POST

I have a chunk of code that does something like this:

require 'net/https'
  PANEL = 'examplehost.com'
  LOGIN_PATH = '/cgi-bin/apps/LogIn'
  @http = Net::HTTP.new(PANEL, 443)
  @http.use_ssl = true
  data = "USERID=xxx&PASSWORD=xxx&StartPage=LOGIN_BALANCES&submit=submit"
  @headers = {
    'Cookie' => get_cookies(),
    'Referer' => 'https://'+PANEL+LOGIN_PATH,
    'Content-Type' => 'application/x-www-form-urlencoded',
    'User-Agent' => USERAGENT
  }
  resp, data = @http.post2(LOGIN_PATH, data, @headers)

I use it for scraping.  There are utility functions in cgi, IIRC, which do encoding, which you might need.

BrewControl.com - Brewery and Brewpub management powered by RoR

Re: How to do https POST

Thanks for the reply.

I have few questions:
1) getCookies() is not defined. How do i do that?
2) will your solution work for endpoints? meaning REST like webservices? where there is no host name?
3) Looks to me you are using methods defined in versions earlier to Ruby 1.8.2
4) Is it possible to modify the following to work with HTTPS?

res = Net::HTTP.post_form(URI.parse('http://jack:pass@www.example.com/todo.cgi'),
                                        {'from'=>'2005-01-01', 'to'=>'2005-03-31'})

Re: How to do https POST

Thanks bkrahmer.  You rock.