Re: Help with a "Post" procedure.

From: Jim Simpson (jimsimpson_at_cox.net)
Date: 06/19/04


Date: Sat, 19 Jun 2004 10:39:08 -0400

In a Google search for other postings on the same subject I happened across
my posting along with a response as follows:
Message 2 in thread
From: Matt Garrish (matthew.garrish@sympatico.ca)
Subject: Re: Help with a "Post" procedure.

View this article only
Newsgroups: comp.lang.perl.misc
Date: 2004-06-18 14:51:24 PST

"Jim Simpson" <jimsimpson@cox.net> wrote in message
news:wgFAc.791$HN5.60@lakeread06...
> I am trying to automate logging in to an HTTPS site which requires a
"user
> name" and "password". It appears to me that the following code should do
the
> job - but it does not do it. Can someone help me out on this.
>
> I'm especially concerned about the "post" line. I do not understand what
> should be in the places where I have used 'text', 'password' and 'submit'.
>

You need to take a step back and learn some basic html. When you submit a
form, each field has (should have!) a name (i.e., <input name="somthing">)
which is used to identify the variable(s) being sent to the server. Username
and password are often used for fields on login pages, but no one says they
have to be. You need to read the source of the page you're trying to log on
to and see what variables actually need to be sent. You can then modify the
post line to send the correct name/value pairs (i.e., fieldname => 'value').

Matt

I don't understand why Matt's response doesn't appear in this listing.

However - thanks Matt for your comment. I should have explained that I did
try to determine what variables should be sent.

 The source code includes the following:
"<input type=text name="username" size="15" maxlength="35"
AUTOCOMPLETE="off">"
That's why I used "text" in my script.

. It also contains the following:
 "<input type="password" name="password" size="15" ONKEYDOWN="return
handleEnterSubmission( this.form , event)" maxlength="35"
AUTOCOMPLETE="off">"
 That's why I used "password".

For the button it includes the following:
 "<input type="image" name="submit" value="Submit"
SRC="/images/login/log_on.gif" border="0">"
I'm not at all sure that the button variable is correct or how the "post"
line of script should indicate that the button is "on".

I need some more help please.

Jim

"Jim Simpson" <jimsimpson@cox.net> wrote in message
news:wgFAc.791$HN5.60@lakeread06...
> I am trying to automate logging in to an HTTPS site which requires a
"user
> name" and "password". It appears to me that the following code should do
the
> job - but it does not do it. Can someone help me out on this.
>
> I'm especially concerned about the "post" line. I do not understand what
> should be in the places where I have used 'text', 'password' and 'submit'.
>
> All help will be greatly appreciated.
>
> Jim
>
> #########################
> #A program to login to a secure site which requires a "user name" and
> password".
> #Load the source code of the site into a Microsoft Word document.
> #Using Windows 98 and ActivePerl v5.8
> #########################
>
> use strict;
> use Data::Dumper;
> use LWP::UserAgent;
> use HTTP::Cookies;
> use Win32::OLE::Const 'Microsoft Word';
>
> my $https_login = 'url of login *** sought';
> my $https_user = 'my user name';
> my $https_pass = 'my password';
>
> #get already active Word application or open new
> my $Word = Win32::OLE->GetActiveObject('Word.Application')
> ||Win32::OLE->new('Word.Application', 'Quit');
>
> my $book = $Word->Documents("PrintOut.doc");
>
> # secure login
> my $ua = LWP::UserAgent->new();
> $ua->protocols_allowed( [ 'https'] );
> $ua->cookie_jar(HTTP::Cookies->new(file => ".cookies.txt", autosave =>
> 1));
> my $response = $ua->post($https_login, [ 'text' => "$https_user",
> 'password' => "$https_pass", 'submit' => "Log On" ] );
>
> $book->words(1)->{'text'} = Dumper($response);
>
>


Quantcast