Help with a "Post" procedure.

J

Jim Simpson

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 sheet 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);
 
M

Matt Garrish

Jim Simpson said:
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
 
J

Jim Simpson

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 ([email protected])
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 said:
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 said:
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 sheet 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);
 
J

Jim Simpson

In my first post I should have explained that I tried to determine the
correct variables to use. I found the following in the source code for the
login sheet that I thought applied to "username" and that is why I used
"text" in my code.
<input type=text name="username" size="15" maxlength="35"
AUTOCOMPLETE="off">

And the following that is why I used "password"
<input type="password" name="password" size="15" ONKEYDOWN="return
handleEnterSubmission( this.form , event)" maxlength="35"
AUTOCOMPLETE="off">

And the following that I assume applies to the "button" confused me - but I
made a stab at it. I'm not sure how I show that the button has been pushed.
<input type="image" name="submit" value="Submit"
SRC="/images/login/log_on.gif" border="0">

Also i understand that some secure sites may encript the data going in. How
can I determine if that is required for this site?

I need more help please.

Jim
 
B

Ben Morrow

[don't top-post]

Quoth "Jim Simpson said:
Jim Simpson said:
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.
my $response = $ua->post($https_login, [ 'text' => "$https_user",
'password' => "$https_pass", 'submit' => "Log On" ] );

In my first post I should have explained that I tried to determine the
correct variables to use. I found the following in the source code for the
login sheet that I thought applied to "username" and that is why I used
"text" in my code.
<input type=text name="username" size="15" maxlength="35"
AUTOCOMPLETE="off">

And the following that is why I used "password"
<input type="password" name="password" size="15" ONKEYDOWN="return
handleEnterSubmission( this.form , event)" maxlength="35"
AUTOCOMPLETE="off">

And the following that I assume applies to the "button" confused me - but I
made a stab at it. I'm not sure how I show that the button has been pushed.
<input type="image" name="submit" value="Submit"
SRC="/images/login/log_on.gif" border="0">

The relevant parameter of <input> is 'name'; so you want

my $response = $ua->post(https_login, [
username => $https_user,
password => $https_pass,
submit => 'Submit',
]);
Also i understand that some secure sites may encript the data going in. How
can I determine if that is required for this site?

That is what https does for you.

Ben
 
J

Joe Smith

Jim said:
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.

That's part of your problem. The name of this textfield is "username",
not "text".
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".

Unless the program is doing something fancy with X and Y values,
just use name="submit" and value="Submit".
-Joe
 
J

Jim Simpson

Thanks to all that responded. It works - now that I understand what's going
on the next site I work on should be a bit easier.

Jim


Ben Morrow said:
[don't top-post]

Quoth "Jim Simpson said:
Jim Simpson said:
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.
my $response = $ua->post($https_login, [ 'text' => "$https_user",
'password' => "$https_pass", 'submit' => "Log On" ] );

In my first post I should have explained that I tried to determine the
correct variables to use. I found the following in the source code for the
login sheet that I thought applied to "username" and that is why I used
"text" in my code.
<input type=text name="username" size="15" maxlength="35"
AUTOCOMPLETE="off">

And the following that is why I used "password"
<input type="password" name="password" size="15" ONKEYDOWN="return
handleEnterSubmission( this.form , event)" maxlength="35"
AUTOCOMPLETE="off">

And the following that I assume applies to the "button" confused me - but I
made a stab at it. I'm not sure how I show that the button has been pushed.
<input type="image" name="submit" value="Submit"
SRC="/images/login/log_on.gif" border="0">

The relevant parameter of <input> is 'name'; so you want

my $response = $ua->post(https_login, [
username => $https_user,
password => $https_pass,
submit => 'Submit',
]);
Also i understand that some secure sites may encript the data going in. How
can I determine if that is required for this site?

That is what https does for you.

Ben
(e-mail address removed)
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top