473,575 Members | 3,507 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;
  7.  
  8. my $ua = LWP::UserAgent->new();
  9. $ua->cookie_jar({});
  10. ($ua, $status) = login($ua, 'webaddress', 'username', 'password');
  11.  
  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.     ];
  25.  
  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. }
  39.  
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
  5.  
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>
  11.  
  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>
  20.  
Thanks in Advance,
Freedolen
Oct 18 '07 #1
4 8584
Freedolen
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')

-Freedolen
Oct 22 '07 #2
numberwhun
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')

-Freedolen
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.

Regards,

Jeff
Oct 22 '07 #3
numberwhun
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.

Regards,

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

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;
  3.  
  4. use strict;
  5.  
  6. my $webaddress = 'baz';
  7. my $user_id = 'foo';
  8. my $passwd = 'bar';
  9.  
  10. my $mech = WWW::Mechanize->new(
  11.     cookie_jar      => {},
  12. #    autocheck       => 1,
  13. #    onerror         => \&Carp::croak,
  14. );
  15.  
  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. }
  21.  
  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. }
  32.  
  33. 1;
  34.  
  35. __END__
  36.  
- Miller
Oct 23 '07 #5

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

Similar topics

4
5616
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...
7
34771
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...
3
3783
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/.....
6
2108
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...
6
9872
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...
6
3233
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...
5
2687
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...
19
3282
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...
9
7789
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...
0
7775
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...
0
8120
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8143
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6515
agi2029
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...
0
3778
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3797
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2286
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
1
1382
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1107
bsmnconsultancy
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...

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.