[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

how to input info in fields on a HTTP page?

Alex Ciarlillo

11/29/2006 3:31:00 PM

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

--
Posted via http://www.ruby-....

4 Answers

Alex Ciarlillo

11/29/2006 8:10:00 PM

0

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/PortalL...)

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>

--
Posted via http://www.ruby-....

Paul Lynch

11/30/2006 9:57:00 AM

0

On 29 Nov 2006, at 20:09, Alex Ciarlillo 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

Paul Lutus

11/30/2006 5:02:00 PM

0

Paul Lynch wrote:

> On 29 Nov 2006, at 20:09, Alex Ciarlillo 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 :-),

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.

--
Paul Lutus
http://www.ara...

Ilya Radchenko

11/30/2006 10:15:00 PM

0

http://wtr.ruby... 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!~




> Paul Lynch wrote:
>
>> On 29 Nov 2006, at 20:09, Alex Ciarlillo 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 :-),
>
> 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.
>
> --
> Paul Lutus
> http://www.ara...
>