Net::HTTP Logging in / Persistent sessions problem

S

Sy Ys

I am able to login to a website at authenticate.domain.com but when I
attempt to visit panel.domain.com it appears the http session has been
lost.

Code:
Net::HTTP.start('authenticate.domain.com',80){|http|
log = http.post('script.php',params)
puts log.body
}

Net::HTTP.start('panel.domain.com',80){|http|
puts http.get('/index.cfm').body
}
 
E

Enrique Comba Riepenhausen

I am able to login to a website at authenticate.domain.com but when I
attempt to visit panel.domain.com it appears the http session has been
lost.

Code:
Net::HTTP.start('authenticate.domain.com',80){|http|
log = http.post('script.php',params)
puts log.body
}

Net::HTTP.start('panel.domain.com',80){|http|
puts http.get('/index.cfm').body
}
--------

So, what could be the problem? Either the second Net::HTTP.start
call is
beginning a new session or the first call is forgetting a vital
cookie.
Anyone? Thanks!

In your code you are basically getting the body of the response only.
Session or cookie information should be in the header... Basically in
a Net::HTTPResponse object you have the Net::HTTPHeader mixed in. Try
looking at the both api's and you'll see it clearly...

Cheers,

Enrique
 
A

Aaron Patterson

I am able to login to a website at authenticate.domain.com but when I
attempt to visit panel.domain.com it appears the http session has been
lost.

Code:
Net::HTTP.start('authenticate.domain.com',80){|http|
log = http.post('script.php',params)
puts log.body
}

Net::HTTP.start('panel.domain.com',80){|http|
puts http.get('/index.cfm').body
}
--------

So, what could be the problem? Either the second Net::HTTP.start call is
beginning a new session or the first call is forgetting a vital cookie.
Anyone? Thanks!

Net::HTTP doesn't save your cookies. If you'd like to have your cookies
automatically saved between each request, check out WWW::Mechanize.

http://mechanize.rubyforge.org/
 
S

Sy Ys

Enrique said:
In your code you are basically getting the body of the response only.
Session or cookie information should be in the header... Basically in
a Net::HTTPResponse object you have the Net::HTTPHeader mixed in. Try
looking at the both api's and you'll see it clearly...

Cheers,

Enrique

Ok, great. After doing some studying I understand a bit more now. Thank
you!

I've got my script logging in but the session still doesn't persist. I
auto-follow a few redirects and I end up back where I was (not logged
in).

I did notice Net::HTTP's get_fields('set-cookie').

Do I need to use set_content_type('set-cookie',@@cookie)? where @@cookie
= get_fields('set-cookie') # of the first login attempt?
 

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,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top