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
Arch::LiteWeb(3pm)					User Contributed Perl Documentation					Arch::LiteWeb(3pm)

NAME
Arch::LiteWeb - simple way to access web pages SYNOPSIS
my $web = Arch::LiteWeb->new; my $content = $web->get("http://some.domain:81/some/path"); die $web->error . " while processing " . $web->request_url unless $content; my $content_type = $web->response_headers->{content_type}; DESCRIPTION
This class provides a basic and easy to use support for the client-side HTTP. It is supplied in order to avoid dependency on LWP. If such dependency is not a problem, consider to use LWP instead that provides much better support for HTTP and other protocols. METHODS
The following class methods are available: get, post, request_url, error, error_with_url, network_error, response_code, response_codestr, response_error, response_headers, response_content. get url [params ...] Execute HTTP get of the given url and return the html string or undef on network/response error. Use other methods to get the details about the error and the response. params is key-value hash, the following keys are supported: url_host - only used if url is none url_port - only used if url is none(80) url_path - only used if url is none endl - default is "1512" timeout - default is 20 seconds user_agent - default is "Arch::LiteWeb/0.1" nocache - add a no-cache header noredirect - don't follow redirect responses max_redirect_depth - default is 5 use_proxy - default is false proxy_url - proxy url ($http_proxy supported too) proxy_host - only used if proxy_url is none proxy_port - only used if proxy_url is none(80) post url input [params] Not implemented yet. request_url Actual url of the last issued request or undef. If partial redirect responses are enabled, then the result is the last (non-redirect) url. error If the last request resulted in error (i.e. get/post returned undef), then this method returns the error message, otherwise it returns undef. This is just a shortcut for network_error || response_error. error_with_url Like error, but with " while fetching request_url " text appended if non undef. network_error The network error message for the last request or undef. response_error The response error message for the last request or undef. response_code The last response code (integer) or undef. response_codestr The last response code (string) or undef. response_headers The last response headers (hashref of HTTP headers) or undef. response_content The last response content or undef. This is the same thing that the last get/post returns. BUGS
Not intended for use in mission-critical applications. AUTHORS
Mikhael Goikhman (migo@homemail.com--Perl-GPL/arch-perl--devel). SEE ALSO
For more information, see LWP, LWP::Simple. perl v5.10.1 2005-03-25 Arch::LiteWeb(3pm)