problems with LWP & HTTP


S

stephenc

Hi

I am trying to log into a secur site using this:

use LWP;
use Crypt::SSLeay;
use HTTP::Request::Common qw(POST);

my $ua = new LWP::UserAgent;




my $req = POST 'https://www.secure.********.com.au/Cardlink/
LoginServlet',
[ 'UserID' => '*********',
'Password' => '********',
'Submit' => 'Submit'
];

print $req->as_string;
my $res = $ua->request($req)
print $response->content();

When I run it at the prompt it hangs after printing print $req-
as_string;

I'm a bit out of my depth. Anyone know how i can get this to return
the page I am lloking for?
 
Ad

Advertisements

S

stephenc

OK, this code does compile but I have had to change my user id and
pasword for obvious reasons:

use LWP;
use Crypt::SSLeay;
use HTTP::Request::Common qw(POST);

my $ua = new LWP::UserAgent;




my $req = POST 'https://www.secure.cardlink.com.au/Cardlink/
LoginServlet',
[ 'UserID' => 'abshidf',
'Password' => 'oddhfhg',
'Submit' => 'Submit'
];

print $req->as_string;
my $res = $ua->request($req);
print $res->content();

It still hangs!

stephenc said:
I am trying to log into a secur site using this:
use LWP;
use Crypt::SSLeay;
use HTTP::Request::Common qw(POST);
my $ua = new LWP::UserAgent;
my $req = POST 'https://www.secure.********.com.au/Cardlink/
LoginServlet',
[ 'UserID' => '*********',
'Password' => '********',
'Submit' => 'Submit'
];
print $req->as_string;
my $res = $ua->request($req)
print $response->content();

last line should be

print $res->content();

Isn't true?

--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)- Hide quoted text -

- Show quoted text -
 
N

Narthring

The UserAgent isn't allowing redirection from a POST. This should fix
the problem.



use LWP;
use Crypt::SSLeay;
use HTTP::Request::Common qw(POST);

my $ua = new LWP::UserAgent;
push @{$ua->requests_redirectable}, 'POST'; #allow redirection
from POST

my $req = POST 'https://www.secure.cardlink.com.au/Cardlink/
LoginServlet',
[ 'UserID' => 'abshidf',
'Password' => 'oddhfhg',
'Submit' => 'Submit'
];

print $req->as_string;
my $res = $ua->request($req);
print $res->content();

OK, this code does compile but I have had to change my user id and
pasword for obvious reasons:

use LWP;
use Crypt::SSLeay;
use HTTP::Request::Common qw(POST);

my $ua = new LWP::UserAgent;

my $req = POST 'https://www.secure.cardlink.com.au/Cardlink/
LoginServlet',
[ 'UserID' => 'abshidf',
'Password' => 'oddhfhg',
'Submit' => 'Submit'
];

print $req->as_string;
my $res = $ua->request($req);
print $res->content();

It still hangs!

stephenc said:
Hi
I am trying to log into a secur site using this:
use LWP;
use Crypt::SSLeay;
use HTTP::Request::Common qw(POST);
my $ua = new LWP::UserAgent;
my $req = POST 'https://www.secure.********.com.au/Cardlink/
LoginServlet',
[ 'UserID' => '*********',
'Password' => '********',
'Submit' => 'Submit'
];
print $req->as_string;
my $res = $ua->request($req)
print $response->content();
last line should be
print $res->content();
Isn't true?

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)- Hide quoted text -
- Show quoted text -
 
S

stephenc

Try this script. Maybe this can help you to find reason ;-)

#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;

print "Content-type: text/html\n\n";

# don't forget to set right values in next line
my $params='UserID=abc&Password=abc&Submit=Submit';

my $ua = LWP::UserAgent->new(timeout => 30);
my $req = HTTP::Request->new(POST =>
'https://www.secure.cardlink.com.au/Cardlink/LoginServlet');
$req->headers->header(Accept => '*/*');
$req->headers->header(Connection => "Keep-Alive");
$req->headers->header(Accept_language => "en");
$req->headers->header(Cache_Control => 'no-cache');
$req->content_type('application/x-www-form-urlencoded');
$req->content($params);
my $res = $ua->request($req);
if ($res->code != 200)
{
print "<html><body>Error: ",$res->code," ",$res->message,"<br>",
"Response:<br>",
"<nobr>&nbsp;Message:&nbsp;$res->{_msg}</nobr><br>",
"<nobr>&nbsp;Protocol:&nbsp;$res->{_protocol}</nobr><br>",
"<nobr>&nbsp;Return code: $res->{_rc}</nobr><br>",
"Response headers:<br>";
foreach (sort keys %{$res->{_headers}})
{
print "<nobr>&nbsp;$_:&nbsp;$res->{_headers}->{$_}</nobr><br>";
}
print "<br><br>Page Content:<br>$res->content" if($res->content);
print "</body></html>";
}
else
{
print $res->content;
}

--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)

I tried this (having changed the parameters but it still hung at this
point:


C:\eventOrganizerV2>d.pl
Content-type: text/html

I tried enabling cookies and opening the preceding page to see if I
pickedany up but it didn't help.

Any further suggestions?
 
Ad

Advertisements

S

stephenc

The UserAgent isn't allowing redirection from a POST. This should fix
the problem.

useLWP;
use Crypt::SSLeay;
use HTTP::Request::Common qw(POST);

my $ua = newLWP::UserAgent;
push @{$ua->requests_redirectable}, 'POST'; #allow redirection
from POST

my $req = POST 'https://www.secure.cardlink.com.au/Cardlink/
LoginServlet',
[ 'UserID' => 'abshidf',
'Password' => 'oddhfhg',
'Submit' => 'Submit'
];

print $req->as_string;
my $res = $ua->request($req);
print $res->content();

OK, this code does compile but I have had to change my user id and
pasword for obvious reasons:
useLWP;
use Crypt::SSLeay;
use HTTP::Request::Common qw(POST);
my $ua = newLWP::UserAgent;
my $req = POST 'https://www.secure.cardlink.com.au/Cardlink/
LoginServlet',
[ 'UserID' => 'abshidf',
'Password' => 'oddhfhg',
'Submit' => 'Submit'
];
print $req->as_string;
my $res = $ua->request($req);
print $res->content();
It still hangs!
stephenc wrote:
Hi
I am trying to log into a secur site using this:
useLWP;
use Crypt::SSLeay;
use HTTP::Request::Common qw(POST);
my $ua = newLWP::UserAgent;
my $req = POST 'https://www.secure.********.com.au/Cardlink/
LoginServlet',
[ 'UserID' => '*********',
'Password' => '********',
'Submit' => 'Submit'
];
print $req->as_string;
my $res = $ua->request($req)
print $response->content();
last line should be
print $res->content();
Isn't true?
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

Hi

I tried that and also enabling cookies and go through the opening page
but it still hangs as the second request. This is te code:

# clearCard.pl



use strict;
use LWP;
use LWP::UserAgent;
use Crypt::SSLeay;

my $browser = LWP::UserAgent -> new;
push @{$browser->requests_redirectable}, 'POST';
$browser->cookie_jar({});


my $response = $browser -> get ('https://www.secure.cardlink.com.au/
Cardlink/login.jsp');

#print $response->content();
print "to here\n";


$response = $browser -> post (
'https://www.secure.cardlink.com.au/Cardlink/LoginServlet',
[
'UserID' => 'abcgsre',
'Password' => 'hfyretsg',
'Submit' => 'Submit'
],
);

$response->is_success or
die "Login failed: ", $response->status_line, "\n";

#print $response->content();


Any further ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top