problems with LWP & HTTP

problems with LWP & HTTP

am 15.08.2007 00:08:40 von 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?

Re: problems with LWP & HTTP

am 15.08.2007 01:03:21 von Bob Walton

stephenc wrote:
....
> 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;
....

When I try it, your code doesn't even compile. Please try again, being
sure to copy/paste your code rather than typing it in.

--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl

Re: problems with LWP & HTTP

am 15.08.2007 01:55:01 von Petr Vileta

stephenc wrote:
> 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.)

Re: problems with LWP & HTTP

am 15.08.2007 08:58:39 von 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!

On Aug 15, 9:55 am, "Petr Vileta" wrote:
> stephenc wrote:
> > 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 -

Re: problems with LWP & HTTP

am 15.08.2007 15:57:38 von 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();

On Aug 15, 1:58 am, stephenc wrote:
> 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!
>
> On Aug 15, 9:55 am, "Petr Vileta" wrote:
>
> > stephenc wrote:
> > > 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 -

Re: problems with LWP & HTTP

am 15.08.2007 17:07:30 von Petr Vileta

stephenc wrote:
> 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',

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 "Error: ",$res->code," ",$res->message,"
",
"Response:
",
" Message: $res->{_msg}
",
" Protocol: $res->{_protocol}
",
" Return code: $res->{_rc}
",
"Response headers:
";
foreach (sort keys %{$res->{_headers}})
{
print " $_: $res->{_headers}->{$_}
";
}
print "

Page Content:
$res->content" if($res->content);
print "";
}
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.)

Re: problems with LWP & HTTP

am 24.08.2007 22:54:43 von stephenc

On Aug 16, 1:07 am, "Petr Vileta" wrote:
> stephenc wrote:
> > 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',
>
> 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 "Error: ",$res->code," ",$res->message,"
",
> "Response:
",
> " Message: $res->{_msg}
",
> " Protocol: $res->{_protocol}
",
> " Return code: $res->{_rc}
",
> "Response headers:
";
> foreach (sort keys %{$res->{_headers}})
> {
> print " $_: $res->{_headers}->{$_}
";
> }
> print "

Page Content:
$res->content" if($res->content);
> print "";
> }
> 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?

Re: problems with LWP & HTTP

am 28.08.2007 06:54:26 von stephenc

On Aug 15, 11:57 pm, Narthring wrote:
> 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();
>
> On Aug 15, 1:58 am, stephenc wrote:
>
>
>
> > 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!
>
> > On Aug 15, 9:55 am, "Petr Vileta" wrote:
>
> > > 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?