473,699 Members | 2,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to login website using LWP and HTTP modules?

17 New Member
Hi All,

I had a perl script which is used to login in a web page, but it gives the error as
"301 Moved Permanently". What does this means and how can it be rectified?
Can anyone help on this?

Code Snippet:
Expand|Select|Wrap|Line Numbers
  1. use HTTP::Cookies;
  2. use HTTP::Request;
  3. use HTTP::Request::Common qw(POST);
  4. use URI::URL;
  5. use HTML::LinkExtor;
  6. use LWP 5.64;
  8. my $ua = LWP::UserAgent->new();
  9. $ua->cookie_jar({});
  10. ($ua, $status) = login($ua, 'webaddress', 'username', 'password');
  12. sub login {
  13.     my ($ua, $login_site, $user_id, $user_pass) = @_;
  14.     $request = POST $login_site, [ 
  15.         username => $user_id,
  16.         passwd   => $user_pass,
  17.         option   => 'login',
  18.         op2      => 'login',
  19.         lang     => 'english',
  20.         return   => 'webaddress',
  21.         message  => '0',
  22.         force_session => '1',
  23.         j3b7d8c5a36287aa77ee125d48b4bd2b2 => '1',
  24.     ];
  26.     push @{ $ua->requests_redirectable }, 'POST'; 
  27.     $response = $ua->request($request);
  28.     $status = $response->is_success;
  29.     if ($status) {
  30.         print("Successfully logged in to $login_site\n"); 
  31.     } else {
  32.         print $response->status_line, "\n";
  33.         print "Login Error: ".$response->status_line."\n";
  34.         print "Unable to Login\n";
  35.         print "Unable to login\n";
  36.     }
  37.     return ($ua, $status);
  38. }
The output what i get is:
Expand|Select|Wrap|Line Numbers
  1. 301 Moved Permanently
  2. Login Error: 301 Moved Permanently
  3. Unable to Login
  4. Unable to login
Below is the form details:
Expand|Select|Wrap|Line Numbers
  1. <form action="webaddress" method="post" name="login" >
  2. Username: <input name="username" id="mod_login_username" type="text" class="inputbox" alt="username" size="10" />
  3. <br />
  4. Password: <input type="password" id="mod_login_password" name="passwd" class="inputbox" size="10" alt="password" />
  5. <br />
  6. <input type="checkbox" name="remember" id="mod_login_remember" class="inputbox" value="yes" alt="Remember Me" />
  7. <label for="mod_login_remember">Remember me</label>
  8. <br />
  9. <input type="submit" name="Submit" class="button" value="Login" />
  10. <a href="webaddress,lostPassword/">    Lost Password?</a>
  12. <input type="hidden" name="option" value="login" />
  13. <input type="hidden" name="op2" value="login" />
  14. <input type="hidden" name="lang" value="english" />
  15. <input type="hidden" name="return" value="webaddress" />
  16. <input type="hidden" name="message" value="0" />
  17. <input type="hidden" name="force_session" value="1" />
  18. <input type="hidden" name="j3b7d8c5a36287aa77ee125d48b4bd2b2" value="1" />
  19. </form>
Thanks in Advance,
Oct 18 '07 #1
4 8587
17 New Member
Since i didn't get reply for the past four days, i have a doubt that my question is not understandable? or shall i post to some other forums(i am asking this b'cos i saw from some other posts as 'dont post the same question to many forums')

Oct 22 '07 #2
3,509 Recognized Expert Moderator Specialist
Since i didn't get reply for the past four days, i have a doubt that my question is not understandable? or shall i post to some other forums(i am asking this b'cos i saw from some other posts as 'dont post the same question to many forums')

My appologies for you question not receiving any attention. I am a little swamped at the moment but will take a look later tonight and see if I can offer you any help, even if anyone else doesn't post.


Oct 22 '07 #3
3,509 Recognized Expert Moderator Specialist
I took a look, and according to this web site, it looks like it has something to do with the URL you are entering. Make sure that it is correct.


Oct 22 '07 #4
1,089 Recognized Expert Top Contributor

The best advice that I can give you is to use [URL http://search.cpan.org/search?query=WW W::Mechanize]WWW::Mechanize[/url] instead of [URL http://search.cpan.org/search?query=LW P::UserAgent]LWP::UserAgent[/url]. Then simply be sure to add error checking at each step of your spidering process. Outputting the full content of each page is generally a good practice during development. And then cross your fingers that they don't ever change their html form. :)

Expand|Select|Wrap|Line Numbers
  1. use Carp;
  2. use WWW::Mechanize;
  4. use strict;
  6. my $webaddress = 'baz';
  7. my $user_id = 'foo';
  8. my $passwd = 'bar';
  10. my $mech = WWW::Mechanize->new(
  11.     cookie_jar      => {},
  12. #    autocheck       => 1,
  13. #    onerror         => \&Carp::croak,
  14. );
  16. # Login Form
  17. my $response = $mech->get($webaddress);
  18. if (!$response->is_success) {
  19.     die "Login page unreachable $webaddress: ",  $response->status_line, "\n";
  20. }
  22. # Login
  23. $mech->form_name("login");
  24. $mech->field('username', $user_id);
  25. $mech->field('passwd', $passwd);
  26. my $response = $mech->click();
  27. if ($response->is_success) {
  28.     print "Login Successful!\n";
  29. } else {
  30.     die "Login failed: ",  $response->status_line, "\n";
  31. }
  33. 1;
  35. __END__
- Miller
Oct 23 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

by: 23s | last post by:
I had this problem in the past, after a server reformat it went away, and now after another server reformat it's back again - no clue what's doing it. Here's the flow: Website root is public, no SSL no forms auth. One of the subfolders in the public area is the root of a "protected" area; SSL is required from this subfolder on forward and a web.config in the subfolder specifies forms authentication. From the public area, I provide a...
by: TJoker .NET | last post by:
I'm developing an VB.NET Windows Forms application that uses CR for VS.NET (original version shipped with VS.NET 2002 - my VS.NET has the latest SP installed, no SPs for CR). My reports get their data from ADO.NET Datasets that are pre-populated by other modules of the application. What I need to do is to use these datasets as the datasources of my reports. Fine, I know how to do that and it works perfectly on my development box. The...
by: Brian F | last post by:
Ok here goes: WEBSITE main directory allows anonymous users fine. SITEA, SITEB, and SITEC are all subdirectories under WEBSITE that refer to graphics and javascript in the main virtual directory. So we have the following structure. /WEBSITE /WEBSITE/images /WEBSITE/js /WEBSITE/SITEA/.....
by: joe t. | last post by:
The subject may sound a little cryptic, so i'll try my best to explain. Details are unavailable, as i am under a nondisclosure agreement, but i'm looking for general principles and tips, not necessarily fixes for existing code. There is a website that requires me to log in using a web-form. Obviously, POST vars are sent and verified and on success i'm given a Session and/or Cookie. Within this logged-in area, there are links leading to...
by: =?Utf-8?B?UGFyYWcgR2Fpa3dhZA==?= | last post by:
Hi All, We have a requirement where we have to develop a custom Login Page which will accept user's NT credentials ( Username , password, domain name). This then needs to be passed to a website which uses Windows Authentication Now my question is how do we pass these credentials to IIS in classic ASP? Would appreciate any help/pointers on this. Thanks in advance.
by: Kat | last post by:
Every time I attempt to run a localhost website, it asks me for a login, as if I am not a user on the local machine. I am a user on the local machine, I am an admin on the local machine. I am not on a network. I have windows xp professional installed, iis is installed and until recently everything worked fine. I am using windows authentication, and have changed everything I can think of to full control, even the Everyone, the vs...
by: rockdale | last post by:
Hi, all: I have a website with its own login page. Now one of my clients want their employees log into my website from their website. They want to have their login page (look and feel are different and hosted on another web server) and then send the user id and pwd to my login page. What is the best to do this? Pass the user id and pwd on the url is not a solution since everybody will see the user's credential.
by: klenwell | last post by:
Another request for comments here. I'd like to accomplish something like the scheme outlined at this page here: http://tinyurl.com/3dtcdr In a nutshell, the form uses javascript to hash (md5) the password field using a random one-time salt (nonce) -- generated by php and pasted in the form -- that is then posted with the hashed password
by: Josh | last post by:
I run a Joomla website and am familiar with php in some but not all aspects. Currently I am trying to find some solutions related to session handling. Am I correct in saying that "login" is kept in sessions? I can see active sessions in my mysql database, but is that the only place this information is stored? Sessions and cookies I know are related also, but how specifically (session info stored in cookies?)? Right now, when users...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.