LWP credentials help

Discussion in 'Perl Misc' started by Nalli, Mar 15, 2007.

  1. Nalli

    Nalli Guest

    use LWP:
    $url = 'https://www.something.com/somethingelse/whatever' ;

    $ua = LWP::UserAgent->new;
    $ua->timeout(45);
    $ua->env_proxy;
    $ua->agent("Mozilla/5.01 (Windows; U; NT4.0; en-us) Gecko/
    25250101");
    $ua->credentials( $url, $url, "username", "password" );
    $response = $ua->get($url);

    if ($response->is_success)
    {
    print $html;
    }

    In order to access $url a username and password are required. The
    problem is that I dont know hwo to pass the credentials in order to
    successfully access the page. Can someone please tell me how to pass
    my login information?

    Thank you in advance.
     
    Nalli, Mar 15, 2007
    #1
    1. Advertising

  2. Nalli

    Jamie Guest

    In <>,
    "Nalli" <> mentions:
    >use LWP:
    > $url = 'https://www.something.com/somethingelse/whatever' ;
    >
    > $ua = LWP::UserAgent->new;
    > $ua->timeout(45);
    > $ua->env_proxy;
    > $ua->agent("Mozilla/5.01 (Windows; U; NT4.0; en-us) Gecko/
    >25250101");
    > $ua->credentials( $url, $url, "username", "password" );
    > $response = $ua->get($url);
    >
    > if ($response->is_success)
    > {
    > print $html;
    > }
    >
    >In order to access $url a username and password are required. The
    >problem is that I dont know hwo to pass the credentials in order to
    >successfully access the page. Can someone please tell me how to pass
    >my login information?


    The way I've done this in the past was to override LWP::UserAgent
    and supply my own get_basic_credentials method. Then, from there
    you can either just return them, prompt the user for them, look them
    up in a database, etc.. Seems a little involved at first, but it's
    not that bad.

    Jamie
    --
    http://www.geniegate.com Custom web programming
    Perl * Java * UNIX User Management Solutions
     
    Jamie, Mar 15, 2007
    #2
    1. Advertising

  3. Nalli

    Peter Scott Guest

    On Thu, 15 Mar 2007 19:27:36 +0000, Jamie wrote:
    > In <>,
    > "Nalli" <> mentions:

    [...]
    >> $ua->agent("Mozilla/5.01 (Windows; U; NT4.0; en-us) Gecko/
    >>25250101");
    >> $ua->credentials( $url, $url, "username", "password" );

    [...]
    >>In order to access $url a username and password are required. The
    >>problem is that I dont know hwo to pass the credentials in order to
    >>successfully access the page. Can someone please tell me how to pass my
    >>login information?

    >
    > The way I've done this in the past was to override LWP::UserAgent and
    > supply my own get_basic_credentials method. Then, from there you can
    > either just return them, prompt the user for them, look them up in a
    > database, etc.. Seems a little involved at first, but it's not that bad.


    And it's precisely because it's involved that I supplied a patch that was
    incorporated into the latest WWW::Mechanize to simplify it. Use that
    module instead and all you need to do is:

    $mech->credentials( $username, $password );

    It should be as easy for the programmer as it is for the browser user,
    otherwise you're doing work that the computer could do for you.

    --
    Peter Scott
    http://www.perlmedic.com/
    http://www.perldebugged.com/
     
    Peter Scott, Mar 16, 2007
    #3
    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. mdh
    Replies:
    0
    Views:
    945
  2. jadher
    Replies:
    1
    Views:
    3,585
    William F. Robertson, Jr.
    Oct 11, 2004
  3. Roy Smith
    Replies:
    0
    Views:
    343
    Roy Smith
    Sep 4, 2006
  4. dan baker

    q about LWP:UserAgent credentials()

    dan baker, Jan 19, 2004, in forum: Perl Misc
    Replies:
    4
    Views:
    106
    dan baker
    Jan 20, 2004
  5. John Stumbles

    LWP::UserAgent credentials netloc and realm

    John Stumbles, May 27, 2005, in forum: Perl Misc
    Replies:
    0
    Views:
    99
    John Stumbles
    May 27, 2005
Loading...

Share This Page