Hi! I’m trying to authenticate to an internal application, and I’m
trying to do it using POST. (I’m also trying to do more stuff than
that, but logging in is kind of a pre-requisite.)
I’m using Net::HTTP – while in my Googling, I’ve seen other gems, 1)
they’re probably not as portable, and b) I’m trying to learn to do it
from scratch before “cheating.”
I’ve pasted both my code (http://pastebin.com/wamKhC9C) and the form
(http://pastebin.com/0ySiHUG6), but here’s a snippet:
------------------------------ cut here ----------------------------
require “net/http”
require “net/https”
require ‘uri’
uri = URI.parse(“https://racon-vod-bo.example.com/login”)
?redirect_to=/host/detail/ccdn-ps-em-02.emeryville.ca.oakl3.comcast.net")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
Get request to get cookies
#resp, data = http.get(“/login”, nil)
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
cookie = response.response[‘set-cookie’]
puts response.body
puts cookie
request = Net::HTTP::Post.new(‘https://racon-vod-bo.example.com/login’)
request.set_form_data({“username” => “ken”, “password” => “Seekrit”})
request[‘Cookie’] = cookie
------------------------------ cut here ----------------------------
Part of my problem, no doubt, is that I’m trying to gel together several
different components (SSL, POST, cookies) that are all interdependent,
which makes it tricky for me to figure one element out well, and move on
to the next. I also apologize for the icky code – I’m just trying to
make it work right now; it’ll get pretty, later.
Any pointers would be most gratefully accepted.
Thanks!
-Ken