# How to input info in fields on a HTTP page?

**URL:** <https://www.ruby-forum.com/t/how-to-input-info-in-fields-on-a-http-page/77665>\
**Category:** Ruby\
**Created:** [November 29, 2006, 4:31pm UTC](https://www.ruby-forum.com/t/how-to-input-info-in-fields-on-a-http-page/77665 "2006-11-29T16:31:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![combas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@combas](https://www.ruby-forum.com/u/combas)\
**Post date:** [November 29, 2006, 4:31pm UTC](https://www.ruby-forum.com/t/how-to-input-info-in-fields-on-a-http-page/77665/1 "2006-11-29T16:31:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![combas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@combas](https://www.ruby-forum.com/u/combas)\
**Post date:** [November 29, 2006, 9:09pm UTC](https://www.ruby-forum.com/t/how-to-input-info-in-fields-on-a-http-page/77665/2 "2006-11-29T21:09:49Z")

</div>

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.

`
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
`

---

<div class="post-metadata">

**Author:** ![combas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@combas](https://www.ruby-forum.com/u/combas)\
**Post date:** [November 30, 2006, 10:57am UTC](https://www.ruby-forum.com/t/how-to-input-info-in-fields-on-a-http-page/77665/3 "2006-11-30T10:57:18Z")

</div>

On 29 Nov 2006, at 20:09, Alex C. wrote:

> 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

---

<div class="post-metadata">

**Author:** ![combas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@combas](https://www.ruby-forum.com/u/combas)\
**Post date:** [November 30, 2006, 7:06pm UTC](https://www.ruby-forum.com/t/how-to-input-info-in-fields-on-a-http-page/77665/4 "2006-11-30T19:06:42Z")

</div>

Paul L. wrote:

> At the risk of incurring the ire of another Paul :-),

No chance of that – I have no emotional investment in that issue. In  
fact I  
am starting to find it rather funny.

I tend to offer an alternative when a library causes more problems than  
it  
solves, something that happens with surprising frequency.

In any case, I realized today I have been making a mistake. I’ve been  
saying, “Why not write your own code?” This is like mentioning abortion  
to  
a fundamentalist – that’s a bad idea, regardless of what one intends to  
say about abortion.

So from now on, I will say, “Why not write your own library?” It’s all  
the  
same – libraries are written using code, and the boundary between a  
piece  
of code and a library is located as precisely as the boundary between  
abortion and the rhythm method. It’s not about reality, it’s about  
avoiding  
trigger words.

People who think outside the box don’t care which words are used to  
describe  
reality, but not everyone thinks outside the box.

This entire library/code issue is not only becoming rather funny, but it  
possesses a huge element of irony, located as it is in a newsgroup for a  
language that was written to get around the limitations of existing  
libraries.

---

<div class="post-metadata">

**Author:** ![combas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@combas](https://www.ruby-forum.com/u/combas)\
**Post date:** [November 30, 2006, 11:15pm UTC](https://www.ruby-forum.com/t/how-to-input-info-in-fields-on-a-http-page/77665/5 "2006-11-30T23:15:40Z")

</div>

## [http://wtr.rubyforge.org/](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.

```
Ilya!~

```
