Help with a "Post" procedure.

Discussion in 'Perl Misc' started by Jim Simpson, Jun 18, 2004.

  1. Jim Simpson

    Jim Simpson Guest

    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);
     
    Jim Simpson, Jun 18, 2004
    #1
    1. Advertising

  2. Jim Simpson

    Matt Garrish Guest

    "Jim Simpson" <> 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
     
    Matt Garrish, Jun 18, 2004
    #2
    1. Advertising

  3. Jim Simpson

    Jim Simpson Guest

    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 ()
    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" <> 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" <> 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 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);
    >
    >
     
    Jim Simpson, Jun 19, 2004
    #3
  4. Jim Simpson

    Jim Simpson Guest

    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



    "Jim Simpson" <> 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 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);
    >
    >
     
    Jim Simpson, Jun 19, 2004
    #4
  5. Jim Simpson

    Ben Morrow Guest

    [don't top-post]

    Quoth "Jim Simpson" <>:
    > "Jim Simpson" <> 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.
    > >

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

    --
    'Deserve [death]? I daresay he did. Many live that deserve death. And some die
    that deserve life. Can you give it to them? Then do not be too eager to deal
    out death in judgement. For even the very wise cannot see all ends.'
     
    Ben Morrow, Jun 20, 2004
    #5
  6. Jim Simpson

    Joe Smith Guest

    Jim Simpson wrote:

    > 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
     
    Joe Smith, Jun 20, 2004
    #6
  7. Jim Simpson

    Jim Simpson Guest

    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" <> wrote in message
    news:cb2jg2$hga$...
    > [don't top-post]
    >
    > Quoth "Jim Simpson" <>:
    > > "Jim Simpson" <> 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.
    > > >

    > <snip>
    > > > 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
    >
    > --
    > 'Deserve [death]? I daresay he did. Many live that deserve death. And some

    die
    > that deserve life. Can you give it to them? Then do not be too eager to

    deal
    > out death in judgement. For even the very wise cannot see all ends.'
    >

     
    Jim Simpson, Jun 20, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oleg
    Replies:
    0
    Views:
    1,176
  2. Sridhar Hegde
    Replies:
    2
    Views:
    2,533
    Ajeetha Kumari
    Sep 13, 2004
  3. Mike P
    Replies:
    0
    Views:
    3,313
    Mike P
    Jun 19, 2006
  4. AlexWare
    Replies:
    2
    Views:
    764
    Paul Uiterlinden
    Oct 23, 2009
  5. Jim Simpson

    Help with a "Post" procedure

    Jim Simpson, Jun 19, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    72
    Jim Simpson
    Jun 19, 2004
Loading...

Share This Page