how to input info in fields on a HTTP page?

A

Alex Ciarlillo

I am trying to figure out how to retrieve reports from a web server. The
problem is the reports dont just exist already, you have to fill in a
bunch of info in a little java applet and the server generates it then
you can download it. The applet has a few tabs for things like date,
locations, report details, and output name. So normally I log into the
page (which I think I can figure out, found plenty of examples) then
start filling in the fields of each tab. Then I click a link to
run/download the report and it pops up the usual "Open/Save As/Cancel"
dialog. So basically I'm kind of lost after I log into the page. I guess
the heart of my question would be how to interact with the java applet
on the page so I can fill in the fields, second to that would be how to
accept the download without being prompted with the dialog box or just
handle it in the background. I have been searching around for a little
while this morning but all the examples have mainly to do with
downloading pictures or something like that which I understand. If you
could point me in the direction of any resources that might help me out
with this I would greatly appreciate it.
Thanks
-a
 
A

Alex Ciarlillo

Okay I got some code working to login to the site Im interested in, but
this led me to a new question. How can I keep this session alive once
logged in? After login I need to follow a link on the page in order to
start posting data to get my reports but I believe the connection is
closing as soon as it posts the login data. I think this requires a
stand alone http object which then processes each request but I havent
had any luck getting this code to work like that. I was also thinking
that I may need to make further requests inside the start block but that
would depend on the case of 'res' so I didnt think that was the right
track. Here is the code I have now, any input would be really
appreciated.

<code>
require 'net/http'
require 'uri'

url = URI.parse('http://xxx.xxx.xxx.xxx/servlet/PortalLogIn/')

req = Net::HTTP::post.new(url.path)
req.set_form_data( {"command" => "login",
"cpny" => "xxx",
"usr" => "xxx",
"pwd" => "xxx" } )

res = Net::HTTP.new(url.host).start { |http| http.request(req) }

case res
when Net::HTTPSuccess, Net::HTTPRedirection
puts "OKAY it worked!"
puts res.body
else
res.error!
end
</code>
 
P

Paul Lynch

Okay I got some code working to login to the site Im interested in,
but
this led me to a new question. How can I keep this session alive once
logged in? After login I need to follow a link on the page in order to
start posting data to get my reports but I believe the connection is
closing as soon as it posts the login data. I think this requires a
stand alone http object which then processes each request but I havent
had any luck getting this code to work like that.

At the risk of incurring the ire of another Paul :), you may be
better off using an external library that can handle this for you. I
have used Mechanize in similar situations with great success.

The problem you are facing, most likely, is that you need to carry
out further actions to maintain the session. This is often something
like receiving and replying with a cookie. I'd be interested to see
if there is a simple way to do this, outside of using Mechanize.

Paul
 
I

Ilya Radchenko

http://wtr.rubyforge.org/ could be what you'r looking for. It's a "Web
Application Testing in Ruby" library, as of now it only works in IE. There
is a project for firefox, but its still in the early stages.
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top