Perl LWP user authentication


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl LWP user authentication
# 1  
Old 05-08-2011
Perl LWP user authentication

Hello all.. i am new to perl scripting.. i wanted to parse a text file, encode the parsed text and attach in url.. please point me to right resources if you know any..This is my major problem. Now i try to get a url running and save it in a text file using LWP module in perl, I used following program to connect to google but getting "401 UNAUTHORIZED" error. please help where i should provide my user authentication details and passwrd.

Code:
#!/usr/bin/perl
    use strict;
    use warnings;
    use LWP::UserAgent;
    use HTTP::Request::Common qw(GET);
    use HTTP::Cookies;

    my $ua = LWP::UserAgent->new;

    # Define user agent type
    $ua->agent('Mozilla/8.0');

    # Cookies
    $ua->cookie_jar(
        HTTP::Cookies->new(
            file => 'mycookies.txt',
            autosave => 1
        )
    );

    # Request object
    my $req = GET 'http://www.google.com';

    # Make the request
    my $res = $ua->request($req);

    # Check the response
    if ($res->is_success) {
        print $res->content;
    } else {
        print $res->status_line . "\n";
    }

    exit 0;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

I want to centralize user authentication

Right now it is just a simple environment consisting of a small number of CentOS boxes, but I would like to set up central user authentication to make things easier, especially as we expand (I've already budgeted to triple our local infrastructure and we will be also expanding geographically to... (1 Reply)
Discussion started by: xdawg
1 Replies

2. Shell Programming and Scripting

parsing a webpage - perl lwp

I am requesting for the text parsing section below. Any helps are highly appreciated. <tr valign="top"><td nowrap>Source name</td> <td style="text-align: justify">Sample Name<br></td> I want Sample Name from above. In the same file, I have to search for another pattern like this <td><a... (1 Reply)
Discussion started by: jacobs.smith
1 Replies

3. Shell Programming and Scripting

perl lwp find word and print next word :)

hi all, I'm new there, I'm just playing with perl and lwp and I just successfully created a script for log in to a web site with post. I have a response but I would like to have something like this: I have in my response lines like: <div class="sender">mimi020</div> <some html code.....>... (3 Replies)
Discussion started by: vogueestylee
3 Replies

4. Shell Programming and Scripting

authentication using LWP

Can some one tell me how to post the username and password using perl LWP. An example is sufficient.. (0 Replies)
Discussion started by: Anjan1
0 Replies

5. Shell Programming and Scripting

Login using perl LWP module

Hi, Could some one tell me how to login to any web site and get that page using perl LWP. I heard that we can login to the site using LWP. I dont want to use WWW:Mechanize as I dont have that module installed on the server. Appreciate your early response. Thanks... (8 Replies)
Discussion started by: Anjan1
8 Replies

6. Web Development

User authentication for some Perl CGI scripts

Hi, I am trying to create a web interface with Perl CGI with 2 pages. The content of these pages is dependent on the user accessing it. Thus, I need some kind of authentication to identify WHO is logging in but I DO NOT WANT to be restricting the pages to a few. What is the best way to prompt... (8 Replies)
Discussion started by: garric
8 Replies

7. Forum Support Area for Unregistered Users & Account Problems

authentication of new user

I recently registered, but never received the email with the instructions for authenticating my account. I confirmed my email in in the profile looks correct. I found and clicked the link to resend the authentication email. I clicked that link two days ago and I still don't have the email. It... (1 Reply)
Discussion started by: dwallace
1 Replies

8. Shell Programming and Scripting

Help needed in Perl LWP module

Hi, I've a issue in writing a perl script that will automatically monitor the site availability. There are two different cookies are set in two consecutive flows to a URL and this second cookie has to be passed to the third step which actually gives permission to access based upon the cookie. ... (1 Reply)
Discussion started by: dayanandra
1 Replies

9. Shell Programming and Scripting

SFTP- Non-interactive user authentication

Hi All, sftp -b script.txt <hostname> user-authentication through non-interactive way is desired. But, its failing to do so. Could anyone kindly advise. Thanks for any/all help at the earliest. Regards, Dheeraj. (1 Reply)
Discussion started by: dheeruchakri
1 Replies

10. Solaris

User Authentication

Ok i need a little help... I have 20 Solaris 8 machines and I would like to have these machines do user authentication through one machine acting as server instead of having to maintain a user list on every machine. What can I do to achieve this? Thanks (3 Replies)
Discussion started by: meyersp
3 Replies
Login or Register to Ask a Question
Authen::Simple::HTTP(3pm)				User Contributed Perl Documentation				 Authen::Simple::HTTP(3pm)

NAME
Authen::Simple::HTTP - Simple HTTP authentication SYNOPSIS
use Authen::Simple::HTTP; my $http = Authen::Simple::HTTP->new( url => 'http://www.host.com/protected' ); if ( $http->authenticate( $username, $password ) ) { # successfull authentication } # or as a mod_perl Authen handler PerlModule Authen::Simple::Apache PerlModule Authen::Simple::HTTP PerlSetVar AuthenSimpleHTTP_url "http://www.host.com/protected" <Location /protected> PerlAuthenHandler Authen::Simple::HTTP AuthType Basic AuthName "Protected Area" Require valid-user </Location> DESCRIPTION
Authenticate against an HTTP server. METHODS
* new This method takes a hash of parameters. The following options are valid: * url Url to authenticate against. Required. url => 'http://www.host.com/protected' * agent Any object that is a subclass of LWP::UserAgent. agent => LWP::UserAgent->new; * log Any object that supports "debug", "info", "error" and "warn". log => Log::Log4perl->get_logger('Authen::Simple::HTTP') * authenticate( $username, $password ) Returns true on success and false on failure. SEE ALSO
Authen::Simple. LWP::UserAgent. LWPx::ParanoidAgent. AUTHOR
Christian Hansen "ch@ngmedia.com" COPYRIGHT
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.8.8 2008-03-01 Authen::Simple::HTTP(3pm)