Help with a "Post" procedure

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

  1. Jim Simpson

    Jim Simpson Guest

    Some of these postings got lost and I have tried to reassemble them.
    Jim

    I am trying to automate loging 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);


    From: Matt Garrish ()
    Subject: Re: Help with a "Post" procedure.


    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

    Matt thanks for responding to my posting.

    I should have explained that I did try 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, Jun 19, 2004
    #1
    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,195
  2. Sridhar Hegde
    Replies:
    2
    Views:
    2,546
    Ajeetha Kumari
    Sep 13, 2004
  3. Mike P
    Replies:
    0
    Views:
    3,328
    Mike P
    Jun 19, 2006
  4. AlexWare
    Replies:
    2
    Views:
    774
    Paul Uiterlinden
    Oct 23, 2009
  5. Jim Simpson

    Help with a "Post" procedure.

    Jim Simpson, Jun 18, 2004, in forum: Perl Misc
    Replies:
    6
    Views:
    98
    Jim Simpson
    Jun 20, 2004
Loading...

Share This Page