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: -
use HTTP::Cookies;
-
use HTTP::Request;
-
use HTTP::Request::Common qw(POST);
-
use URI::URL;
-
use HTML::LinkExtor;
-
use LWP 5.64;
-
-
my $ua = LWP::UserAgent->new();
-
$ua->cookie_jar({});
-
($ua, $status) = login($ua, 'webaddress', 'username', 'password');
-
-
sub login {
-
my ($ua, $login_site, $user_id, $user_pass) = @_;
-
$request = POST $login_site, [
-
username => $user_id,
-
passwd => $user_pass,
-
option => 'login',
-
op2 => 'login',
-
lang => 'english',
-
return => 'webaddress',
-
message => '0',
-
force_session => '1',
-
j3b7d8c5a36287aa77ee125d48b4bd2b2 => '1',
-
];
-
-
push @{ $ua->requests_redirectable }, 'POST';
-
$response = $ua->request($request);
-
$status = $response->is_success;
-
if ($status) {
-
print("Successfully logged in to $login_site\n");
-
} else {
-
print $response->status_line, "\n";
-
print "Login Error: ".$response->status_line."\n";
-
print "Unable to Login\n";
-
print "Unable to login\n";
-
}
-
return ($ua, $status);
-
}
-
The output what i get is: -
301 Moved Permanently
-
Login Error: 301 Moved Permanently
-
Unable to Login
-
Unable to login
-
Below is the form details: -
<form action="webaddress" method="post" name="login" >
-
Username: <input name="username" id="mod_login_username" type="text" class="inputbox" alt="username" size="10" />
-
<br />
-
Password: <input type="password" id="mod_login_password" name="passwd" class="inputbox" size="10" alt="password" />
-
<br />
-
<input type="checkbox" name="remember" id="mod_login_remember" class="inputbox" value="yes" alt="Remember Me" />
-
<label for="mod_login_remember">Remember me</label>
-
<br />
-
<input type="submit" name="Submit" class="button" value="Login" />
-
<a href="webaddress,lostPassword/"> Lost Password?</a>
-
-
<input type="hidden" name="option" value="login" />
-
<input type="hidden" name="op2" value="login" />
-
<input type="hidden" name="lang" value="english" />
-
<input type="hidden" name="return" value="webaddress" />
-
<input type="hidden" name="message" value="0" />
-
<input type="hidden" name="force_session" value="1" />
-
<input type="hidden" name="j3b7d8c5a36287aa77ee125d48b4bd2b2" value="1" />
-
</form>
-
Thanks in Advance,
Freedolen
4 8581
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
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
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
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. :) -
use Carp;
-
use WWW::Mechanize;
-
-
use strict;
-
-
my $webaddress = 'baz';
-
my $user_id = 'foo';
-
my $passwd = 'bar';
-
-
my $mech = WWW::Mechanize->new(
-
cookie_jar => {},
-
# autocheck => 1,
-
# onerror => \&Carp::croak,
-
);
-
-
# Login Form
-
my $response = $mech->get($webaddress);
-
if (!$response->is_success) {
-
die "Login page unreachable $webaddress: ", $response->status_line, "\n";
-
}
-
-
# Login
-
$mech->form_name("login");
-
$mech->field('username', $user_id);
-
$mech->field('passwd', $passwd);
-
my $response = $mech->click();
-
if ($response->is_success) {
-
print "Login Successful!\n";
-
} else {
-
die "Login failed: ", $response->status_line, "\n";
-
}
-
-
1;
-
-
__END__
-
- Miller
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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. ...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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...
|
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...
|
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...
|
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...
|
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.
| |